Next: Syntax of numerical constants, Previous: Implementation restrictions, Up: Numbers [Index]
Implementations may provide more than one representation of floating-point
numbers with differing precisions. In an implementation which does so, an
inexact result must be represented with at least as much precision as is
used to express any of the inexact arguments to that operation. Although
it is desirable for potentially inexact operations such as sqrt
to produce exact answers when applied to exact arguments, if an exact
number is operated upon so as to produce an inexact result, then the
most precise representation available must be used. For example, the
value of (sqrt 4)
should be 2
, but in an implementation
that provides both single and double precision floating point numbers
it may be the latter but must not be the former.
It is the programmer’s responsibility to avoid using inexact number objects with magnitude or significand too large to be represented in the implementation.
In addition, implementations may distinguish special numbers called positive infinity, negative infinity, NaN, and negative zero.
Positive infinity is regarded as an inexact real (but not rational) number that represents an indeterminate value greater than the numbers represented by all rational numbers. Negative infinity is regarded as an inexact real (but not rational) number that represents an indeterminate value less than the numbers represented by all rational numbers.
Adding or multiplying an infinite value by any finite real value results in an appropriately signed infinity; however, the sum of positive and negative infinities is a NaN. Positive infinity is the reciprocal of zero, and negative infinity is the reciprocal of negative zero. The behavior of the transcendental functions is sensitive to infinity in accordance with IEEE 754.
A NaN is regarded as an inexact real (but not rational) number so
indeterminate that it might represent any real value, including positive
or negative infinity, and might even be greater than positive infinity
or less than negative infinity. An implementation that does not support
non-real numbers may use NaN to represent non-real values like
(sqrt -1.0)
and (asin 2.0)
.
A NaN always compares false to any number, including a NaN. An arithmetic operation where one operand is NaN returns NaN, unless the implementation can prove that the result would be the same if the NaN were replaced by any rational number. Dividing zero by zero results in NaN unless both zeros are exact.
Negative zero is an inexact real value written -0.0
and is distinct
(in the sense of eqv?
) from 0.0
. A Scheme implementation
is not required to distinguish negative zero. If it does, however, the
behavior of the transcendental functions is sensitive to the distinction
in accordance with IEEE 754. Specifically, in a Scheme implementing
both complex numbers and negative zero, the branch cut of the complex
logarithm function is such that (imag-part (log -1.0-0.0i))
is -π rather than π.
Furthermore, the negation of negative zero is ordinary zero and vice versa. This implies that the sum of two or more negative zeros is negative, and the result of subtracting (positive) zero from a negative zero is likewise negative. However, numerical comparisons treat negative zero as equal to zero.
Note that both the real and the imaginary parts of a complex number can be infinities, NaNs, or negative zero.
Next: Syntax of numerical constants, Previous: Implementation restrictions, Up: Numbers [Index]