ex to double

Markus Knodel mknodel at thep.physik.uni-mainz.de
Wed Oct 15 13:51:22 CEST 2003

Hi Volker,

> I am a new user to ginac, and i am trying to find out how to convert an ex to a double.
> This of course only makes sense when ex contains something that is a double.
> I have been searching the tutorial and tried "expresion output".
> There it explains in section 5.12.1 how to  manipulate the outputstream with
> "csrc"  but I can not get the examples working. I also dont know if this is the
> right way get my double.

If I undestood your question correctely, it is much easier than you think.
The answer has nothing to do with expression output or something like
this. You must just convert the ex to a numeric and this to a double:

#include <iostream>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;

int main(){

    ex poly=2.7;
    double val = ( ex_to<numeric>( poly ) ).to_double();
    cout << val << endl;
    return 0;

Is this the answer of your question?


More information about the GiNaC-list mailing list