[GiNaC-list] converting expressions to double

Tomasz I. Rudny rudnyt at gmail.com
Fri Mar 2 12:01:38 CET 2012


Hello,

Thank you for GiNaC and your support - I have almost completed my PhD
with it :)

But I have a little problem still...

I have a symbolic expression F(x, y, z, u) and I need to 1) substitute
x, y, z, u with values (given as double), 2) calculate F, 3) export F as
double.

My code looks like this:

double my_method(GiNaC::ex & ex, double x1, double y1,
		double z1, double u1) {
	numeric _x(x1), _y(y1), _z(z1), _u(u1);
	ex = ex.subs(lst(x == _x, y == _y, z == _z, u == _u));
	ex = ex.evalf();
	numeric tmp = ex_to<numeric>(ex);
	return tmp.to_double();
}


Unfortunately, the last instruction (to_double() ) fails and throws the
exception:

terminate called after throwing an instance of 'cln::notreached_exception'
  what():  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!

I read the response cited below, but still I can't fix it.

Could you please help me?

Thank you very much,
Tomasz.
Warsaw University of Technology


=========================

Hi!

On 11/02/2010 08:12 AM, Sebastian Luther wrote:
> below you'll find a small test program that crashes for me.
>
> --------------------------------------------
> #include<ginac/ginac.h>
> #include<iostream>
>
> int main(int argc, char* argv[])
> {
> 	GiNaC::parser p;
> 	GiNaC::ex e = p("941480149401/1250000000000000*2^(5/91)");
> 	GiNaC::numeric n = GiNaC::ex_to<GiNaC::numeric>(e);
> 	double x = n.to_double(); //throws the exception below
> 	return 0;
> }

Since e is a product (of a rational number and a power of two) it must
be converted to a number using evalf() before trying to assign it to a
simple numeric object.

> Looks like the real problem lays in cln, but I'm not sure how to
reproduce it there.

It has nothing to do with CLN.

Best wishes
    -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>


More information about the GiNaC-list mailing list