Hi, 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. #include <iostream> #include <stdio.h> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main(){ ex poly=2.7; double val; std::ostream & csrc(std::ostream & os); cout << csrc <<poly <<"\n"; return 0; } When I run the example above I get the error below, and I don not know how to handle it. /tmp/cczNv1jd.o: In function `main': /tmp/cczNv1jd.o(.text+0x36): undefined reference to `csrc(ostream &)' collect2: ld returned 1 exit status I am working wih ginac version : 1.1.1 g++: 2.95.3 I am not that much intro programming to understand how stream manipulation really works and to understand the ginac source code. Can anyone help me to get my double ?? Saludos de EspaƱa, Volker ______________________________________________________________________________ Horoskop, Comics, VIPs, Wetter, Sport und Lotto im WEB.DE Screensaver1.2 Kostenlos downloaden: http://screensaver.web.de/?mc=021110
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? Cheers Markus
participants (2)
-
Markus Knodel
-
Volker Vogel