Behavior of numeric::to_int() and numeric::to_long()

Roberto Bagnara bagnara at
Tue Oct 1 16:18:28 CEST 2002

Richard B. Kreckel wrote:
> On Tue, 1 Oct 2002, Roberto Bagnara wrote:
>>These methods, and the corresponding functions taking
>>the argument as a const numeric& parameter, when something
>>goes wrong print a line of the form
>>Not a 32-bit integer: -9223372028264841216
>>on cerr and exit the program.  Wouldn't throwing a
>>suitable standard exception (like std::domain_error)
>>be a better option?
> Not really.  We want them to be fast.  They are intended for use in main
> loops only and if you look into the code you'll see that we don't even
> check whether they are actual integers.  The programmer should care about
> that...

I agree on what you say.  This is even stated in the documentation.

What I am saying is that, instead of writing "Not a 32-bit integer..."
and exiting, you could throw an exception.  This would not impede
performance, since the test now controlling the printing would then
control the throw.  The change I am proposing would make debugging
much easier and would make possible recovering from the error (and
this is the thing that is very important to us).
All the best


Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
mailto:bagnara at

More information about the GiNaC-list mailing list