Next: , Previous: Complex Numbers, Up: Numbers

##### 5.5.2.5 Exact and Inexact 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.

— 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.