Hi, I have a question about error handling. I have a problem with the "Floating point overflow". May be is better if I give an example: #include<iostream> #include<fstream> #include<string> #include<ginac/ginac.h> int main(void) { try{ GiNaC::realsymbol x("x"); GiNaC::ex pp("sin(sin(sin(sin(log(-0.760)))))",GiNaC::lst(x)); cout << pp << endl; }catch(exception &p){ cout << p.what() <<endl; } cout << "With or without exceptions\n" <<endl; } (If you are thinking where I found that absurd function...well, this is another story) When run this program it stops and gives : "Floating point overflow". This is related to the fact that Ginac tries to evaluate the numeric expression. So I have two questions: 1) Why does it not throw and exception? 2) Is it possible to stop ginac tries to evaluate the numeric expressions? Thanks in advance, Alberto
Caro Alberto,
GiNaC::ex pp("sin(sin(sin(sin(log(-0.760)))))",GiNaC::lst(x));
1) Why does it not throw and exception?
Numerical evaluations are delegated to the underlying CLN library. That library does not do exceptions.
2) Is it possible to stop ginac tries to evaluate the numeric expressions?
Yes, but not from a string. In normal code you can type sin(sin(sin(sin(log(-0.760).hold())))) The .hold() method is used to indicate that an object should not be evaluated. Saluti, Chris
Hello! On Thu, Mar 29, 2007 at 01:37:32PM +0200, Chris.Dams@mi.infn.it wrote:
2) Is it possible to stop ginac tries to evaluate the numeric expressions?
Yes, but not from a string. In normal code you can type
sin(sin(sin(sin(log(-0.760).hold()))))
I used to think that GiNaC does not evaluate expressions numerically unless evalf() is called. Apparently this is not true. I think this is a bug which should be fixed. Best regards, Alexei -- All science is either physics or stamp collecting.
Dear Alexei, On Thu, 29 Mar 2007, Sheplyakov Alexei wrote:
Yes, but not from a string. In normal code you can type
sin(sin(sin(sin(log(-0.760).hold()))))
I used to think that GiNaC does not evaluate expressions numerically unless evalf() is called. Apparently this is not true. I think this is a bug which should be fixed.
I do not see a problem with it. I think it is almost always the right thing to do. This behaviour was intended as is clear from this code fragment from exp_eval // exp(float) -> float if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) return exp(ex_to<numeric>(x)); I am afraid that changing this behaviour would break quite a lot of code out there. Best wishes, Chris
Hi! Sheplyakov Alexei wrote:
I used to think that GiNaC does not evaluate expressions numerically unless evalf() is called. Apparently this is not true. I think this is a bug which should be fixed.
Regarding .eval(), the idea is to evaluate numerically if and only if there is no exact value to be preserved. Integers and rationals are exact, floats not. Hence: sin(3/2) -> sin(3/2) sin(1.5) -> 0.9974949866040544309 Bye -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Numerical evaluations are delegated to the underlying CLN library. That library does not do exceptions.
Ah, ok. I try to work with cln error handling, but without much success. I will find another way. Ciao Alberto
2) Is it possible to stop ginac tries to evaluate the numeric expressions?
Yes, but not from a string. In normal code you can type
sin(sin(sin(sin(log(-0.760).hold()))))
The .hold() method is used to indicate that an object should not be evaluated.
Saluti, Chris
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
participants (5)
-
Alberto Orlandi
-
Chris Dams
-
Chris.Dams@mi.infn.it
-
Richard B. Kreckel
-
varg@theor.jinr.ru