Next: Floating-point Computations, Previous: Implementation-Dependent Numeric Constants, Up: Number Concepts
The rules in this section apply to rational computations.
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.
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
.
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))
.
|
Figure 12.8: Functions Affected by Rule of Float Substitutability