Next: Number Syntax, Previous: Complex Numbers, Up: Numbers
R5RS requires that a calculation involving inexact numbers always
produces an inexact result. To meet this requirement, Guile
distinguishes between an exact integer value such as `5' and the
corresponding inexact real value which, to the limited precision
available, has no fractional part, and is printed as `5.0'. Guile
will only convert the latter value to the former when forced to do so by
an invocation of the inexact->exact
procedure.
Return
#t
if the number z is exact,#f
otherwise.(exact? 2) => #t (exact? 0.5) => #f (exact? (/ 2)) => #t
Return
#t
if the number z is inexact,#f
else.
Return an exact number that is numerically closest to z, when there is one. For inexact rationals, Guile returns the exact rational that is numerically equal to the inexact rational. Inexact complex numbers with a non-zero imaginary part can not be made exact.
(inexact->exact 0.5) => 1/2The following happens because 12/10 is not exactly representable as a
double
(on most platforms). However, when reading a decimal number that has been marked exact with the “#e” prefix, Guile is able to represent it correctly.(inexact->exact 1.2) => 5404319552844595/4503599627370496 #e1.2 => 6/5