Next: , Previous: Implementation-Dependent Numeric Constants, Up: Number Concepts

#### 12.1.3 Rational Computations

The rules in this section apply to rational computations.

##### 12.1.3.1 Rule of Unbounded Rational Precision

Rational computations cannot overflow in the usual sense (though there may not be enough storage to represent a result), since integers and ratios may in principle be of any magnitude.

##### 12.1.3.2 Rule of Canonical Representation for Rationals

If any computation produces a result that is a mathematical ratio of two integers such that the denominator evenly divides the numerator, then the result is converted to the equivalent integer.

If the denominator does not evenly divide the numerator, the canonical representation of a rational number is as the ratio that numerator and that denominator, where the greatest common divisor of the numerator and denominator is one, and where the denominator is positive and greater than one.

When used as input (in the default syntax), the notation `-0` always denotes the integer `0`. A conforming implementation must not have a representation of “minus zero” for integers that is distinct from its representation of zero for integers. However, such a distinction is possible for floats; see the type `float`.

##### 12.1.3.3 Rule of Float Substitutability

When the arguments to an irrational mathematical function

are all rational and the true mathematical result is also (mathematically) rational, then unless otherwise noted an implementation is free to return either an accurate rational result or a single float approximation. If the arguments are all rational but the result cannot be expressed as a rational number, then a single float approximation is always returned.

If the arguments to an irrational mathematical function are all of type `(or rational (complex rational))` and the true mathematical result is (mathematically) a complex number with rational real and imaginary parts, then unless otherwise noted an implementation is free to return either an accurate result of type `(or rational (complex rational))` or a single float (permissible only if the imaginary part of the true mathematical result is zero) or `(complex single-float)`. If the arguments are all of type `(or rational (complex rational))` but the result cannot be expressed as a rational or complex rational, then the returned value will be of type `single-float` (permissible only if the imaginary part of the true mathematical result is zero) or `(complex single-float)`.

Float substitutability applies neither to the rational functions `+`, `-`, `*`, and `/` nor to the related operators `1+`, `1-`, `incf`, `decf`, and `conjugate`. For rational functions, if all arguments are rational, then the result is rational; if all arguments are of type `(or rational (complex rational))`, then the result is of type `(or rational (complex rational))`.

Function Sample Results
`abs` `(abs #c(3 4)) `` 5 `or` 5.0`
`acos` `(acos 1) `` 0 `or` 0.0`
`acosh` `(acosh 1) `` 0 `or` 0.0`
`asin` `(asin 0) `` 0 `or` 0.0`
`asinh` `(asinh 0) `` 0 `or` 0.0`
`atan` `(atan 0) `` 0 `or` 0.0`
`atanh` `(atanh 0) `` 0 `or` 0.0`
`cis` `(cis 0) `` 1 `or` #c(1.0 0.0)`
`cos` `(cos 0) `` 1 `or` 1.0`
`cosh` `(cosh 0) `` 1 `or` 1.0`
`exp` `(exp 0) `` 1 `or` 1.0`
`expt` `(expt 8 1/3) `` 2 `or` 2.0`
`log` `(log 1) `` 0 `or` 0.0`
`(log 8 2) `` 3 `or` 3.0`
`phase` `(phase 7) `` 0 `or` 0.0`
`signum` `(signum #c(3 4)) `` #c(3/5 4/5) `or` #c(0.6 0.8)`
`sin` `(sin 0) `` 0 `or` 0.0`
`sinh` `(sinh 0) `` 0 `or` 0.0`
`sqrt` `(sqrt 4) `` 2 `or` 2.0`
`(sqrt 9/16) `` 3/4 `or` 0.75`
`tan` `(tan 0) `` 0 `or` 0.0`
`tanh` `(tanh 0) `` 0 `or` 0.0`

Figure 12.8: Functions Affected by Rule of Float Substitutability