manpagez: man pages & more
info guile
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.2.5 Exact and Inexact Numbers

R5RS requires that, with few exceptions, 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 integer 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.

The only exception to the above requirement is when the values of the inexact numbers do not affect the result. For example (expt n 0) is ‘1’ for any value of n, therefore (expt 5.0 0) is permitted to return an exact ‘1’.

Scheme Procedure: exact? z
C Function: scm_exact_p (z)

Return #t if the number z is exact, #f otherwise.

 
(exact? 2)
⇒ #t

(exact? 0.5)
⇒ #f

(exact? (/ 2))
⇒ #t
Scheme Procedure: inexact? z
C Function: scm_inexact_p (z)

Return #t if the number z is inexact, #f else.

Scheme Procedure: inexact->exact z
C Function: scm_inexact_to_exact (z)

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/2

The 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
Scheme Procedure: exact->inexact z
C Function: scm_exact_to_inexact (z)

Convert the number z to its inexact representation.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2026
Individual documents may contain additional copyright information.