7.2.1 Transform a floating point number into a rational
Rational numbers can be approximated by floating point numbers, but
since floating point numbers are not exact, they cannot typically be
converted back to the original rational number. However, the
float2rational
or exact
command will try convert a floating point to a nearby rational number.
-
float2rational takes
d, a floating point number.
- float2rational(d) returns
a rational number q close to d; namely such that
|d−q|<epsilon, where epsilon is defined in the
CAS configuration (Cfg menu, see
Section 2.5.7, item 2.5.7) or with the
cas_setup command (see Section 2.5.10).
Examples
float2rational(0.3670520231) |
Output for epsilon=1e-10:
float2rational(12.9642857143) |
If two representations are mixed, for example:
the rational is converted to a float.