[GiNaC-list] Internal error: statement in file
./real/conv/cl_R_to_double.cc, line 55 has been reached!!
Sheplyakov Alexei
varg at theor.jinr.ru
Fri Dec 8 13:41:33 CET 2006
Hello!
On Fri, Dec 08, 2006 at 12:14:42PM +0000, Pedro Cruz wrote:
> Hi,
>
> --------------------
> this output
> --------------------
>
> Pi=3.1415926535897932385
> Internal error: statement in file ./real/conv/cl_R_to_double.cc, line 55
> has been reached!!
> Please send the authors of the program a description how you produced
> this error!
>
> --------------------
> has been produced by
> --------------------
>
>
> #include <iostream>
> #include <sstream>
> #include <stdexcept>
> #include <ginac/ginac.h>
> using namespace std;
> using namespace GiNaC;
>
>
> int main()
> {
> cout << "Pi=" << Pi.evalf() << endl;
>
> if (is_a<constant>(Pi)) {
> double f = ex_to<numeric>(Pi).to_double();
> cout << f << endl;
> }
>
> return 0;
> }
ex_to is unsafe function (this is documented in the manual), so you
should check if the expression in question is really of type T before
converting it with ex_to<T> (unless you *really* know what are you doing).
Pi is not numeric, but a contstant, so your code is expected to fail.
> ---------------------------------------------
> on debian (etch testing) with libginac1.3c2a.
> ---------------------------------------------
>
> It was a first example i tried to do
> in order to understand ginac/cln concepts:
> <ex>
> <constant> and
> <numeric>.
>
> How to convert from Pi to C++ double type in one C++ line ?
Quoting the manual:
"GiNaC keeps algebraic expressions, numbers and constants in their exact
form. To evaluate them using floating-point arithmetics you need to call
ex ex::evalf(int level = 0) const;"
So, use something like this:
double f = ex_to<numeric>(Pi.evalf()).to_double();
Also you could try this patch:
http://www.ginac.de/pipermail/ginac-list/2006-October/000993.html
Using this patch the same code can be written as:
double f;
numconv_to(Pi, f);
Best regards,
Alexei
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20061208/b7a16c45/attachment.pgp
More information about the GiNaC-list
mailing list