Extracting a numeric from an ex
Continuing the previous message... I would find it extremely useful if it was possible to get a numeric representing the ex's contents, _if_ that is possible, of course. Specifically, it would a be a function like this: class ex { .... numeric to_numeric() const; .... } Or any other significant name. Of course, there are times when a numeric cannot represent an ex. In these cases, the most appropriate solution seems to throw an exception, but other ways of allerting the user are possible. Another function, returning a bool saying wheter the ex can be converted into a numeric would also be nice. Is the above possible? -- The church is near but the road is icy; the bar is far away but I will walk carefully. -- Russian Proverb Eduardo M Kalinowski (ekalin@iname.com) http://move.to/hpkb http://cami-ufpr.hpg.com.br - To UNSUBSCRIBE, email to ginac-list@ginac.de with a subject of "unsubscribe".
Hi! On Wed, Dec 06, 2000 at 02:39:29PM -0200, Eduardo M Kalinowski wrote:
I would find it extremely useful if it was possible to get a numeric representing the ex's contents
Given an 'ex e': numeric n; if (is_ex_of_type(e, numeric)) n = ex_to_numeric(e); Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/ - To UNSUBSCRIBE, email to ginac-list@ginac.de with a subject of "unsubscribe".
Christian Bauer wrote:
Hi!
On Wed, Dec 06, 2000 at 02:39:29PM -0200, Eduardo M Kalinowski wrote:
I would find it extremely useful if it was possible to get a numeric representing the ex's contents
Given an 'ex e':
numeric n; if (is_ex_of_type(e, numeric)) n = ex_to_numeric(e);
Since this is not documented in the tutorial, and is difficult to be found in the reference, I've made some little changes to the tutorial to include description for that (and related functions.) Feel free to use, change, ignore, etc. the patch, Richard. -- I tell ya, I was an ugly kid. I was so ugly that my dad kept the kid's picture that came with the wallet he bought. -- Rodney Dangerfield Eduardo M Kalinowski (ekalin@iname.com) http://move.to/hpkb http://cami-ufpr.hpg.com.br --- ginac.texi.old Thu Dec 7 21:37:01 2000 +++ ginac.texi Thu Dec 7 21:57:19 2000 @@ -1298,10 +1298,13 @@ @c node-name, next, previous, up @section Getting information about expressions @subsection Checking expression types @cindex @code{is_ex_of_type()} +@cindex @code{ex_to_numeric()} +@cindex @code{ex_to_...} +@cindex @code{Converting ex to other classes} @cindex @code{info()} Sometimes it's useful to check whether a given expression is a plain number, a sum, a polynomial with integer coefficients, or of some other specific type. GiNaC provides two functions for this (the first one is actually a macro): @@ -1325,10 +1328,24 @@ is_ex_of_type(e2, numeric); // false is_ex_of_type(e1, add); // false is_ex_of_type(e2, add); // true is_ex_of_type(e1, mul); // false is_ex_of_type(e2, mul); // false +@} +@end example + +When the test made by @code{is_ex_of_type()} returns true, it is safe to +call one of the functions @code{ex_to_...}, where @code{...} is one of +the class names (@xref{The Class Hierarchy}, for a list of all +classes). For example: + +@example +@{ + ... + if (is_ex_of_type(e, numeric)) + GiNaC::numeric n = ex_to_numeric(e); + ... @} @end example The @code{info()} method is used for checking certain attributes of expressions. The possible values for the @code{flag} argument are defined
Hi Eduardo, On Thu, 7 Dec 2000, Eduardo M Kalinowski wrote:
Since this is not documented in the tutorial, and is difficult to be found in the reference, I've made some little changes to the tutorial to include description for that (and related functions.) Feel free to use, change, ignore, etc. the patch, Richard.
Thank you. It's in. Regards -richy. -- Richard Kreckel <Richard.Kreckel@Uni-Mainz.DE> <http://wwwthep.physik.uni-mainz.de/~kreckel/> - To UNSUBSCRIBE, email to ginac-list@ginac.de with a subject of "unsubscribe".
participants (3)
-
Christian Bauer
-
Eduardo M Kalinowski
-
Richard B. Kreckel