[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.11.2 Conversion to rational numbers
Each of the classes cl_R
, cl_RA
, cl_F
defines the following operation:
cl_RA rational (const type& x)
-
Returns the value of
x
as an exact number. Ifx
is already an exact number, this isx
. Ifx
is a floating-point number, the value is a rational number whose denominator is a power of 2.
In order to convert back, say, (cl_F)(cl_R)"1/3"
to 1/3
, there is
the function
cl_RA rationalize (const cl_R& x)
-
If
x
is a floating-point number, it actually represents an interval of real numbers, and this function returns the rational number with smallest denominator (and smallest numerator, in magnitude) which lies in this interval. Ifx
is already an exact number, this function returnsx
.
If x
is any float, one has
-
cl_float(rational(x),x) = x
-
cl_float(rationalize(x),x) = x
This document was generated on August 27, 2013 using texi2html 5.0.