[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.6.3 Converting numbers
Sometimes it is desirable to convert a numeric
object back to a
built-in arithmetic type (int
, double
, etc.). The numeric
class provides a couple of methods for this purpose:
int numeric::to_int() const; long numeric::to_long() const; double numeric::to_double() const; cln::cl_N numeric::to_cl_N() const; |
to_int()
and to_long()
only work when the number they are
applied on is an exact integer. Otherwise the program will halt with a
message like ‘Not a 32-bit integer’. to_double()
applied on a
rational number will return a floating-point approximation. Both
to_int()/to_long()
and to_double()
discard the imaginary
part of complex numbers.