20 Revised
5
Scheme
is inexact if it was written as an inexact constant, if it
was derived using inexact ingredients, or if it was derived
using inexact operations. Thus inexactness is a contagious
property of a number.
If two implementations produce exact results for a com-
putation that did not involve inexact intermediate results,
the two ultimate results will be mathematically equivalent.
This is generally not true of computations involving inex-
act numbers since approximate methods such as floating
point arithmetic may be used, but it is the duty of each
implementation to make the result as close as practical to
the mathematically ideal result.
Rational operations such as + should always produce ex-
act results when given exact arguments. If the operation
is unable to produce an exact result, then it may either
report the violation of an implementation restriction or it
may silently coerce its result to an inexact value. See sec-
tion 6.2.3.
With the exception of inexact->exact, the operations de-
scribed in this section must generally return inexact results
when given any inexact arguments. An operation may,
however, return an exact result if it can prove that the
value of the result is unaffected by the inexactness of its
arguments. For example, multiplication of any number by
an exact zero may produce an exact zero result, even if the
other argument is inexact.
6.2.3. Implementation restrictions
Implementations of Scheme are not required to implement
the whole tower of subtypes given in section 6.2.1, but
they must implement a coherent subset consistent with
both the purposes of the implementation and the spirit
of the Scheme language. For example, an implementation
in which all numbers are real may still be quite useful.
Implementations may also support only a limited range of
numbers of any type, subject to the requirements of this
section. The supported range for exact numbers of any
type may be different from the supported range for inex-
act numbers of that type. For example, an implementation
that uses flonums to represent all its inexact real numbers
may support a practically unbounded range of exact inte-
gers and rationals while limiting the range of inexact reals
(and therefore the range of inexact integers and rationals)
to the dynamic range of the flonum format. Furthermore
the gaps between the representable inexact integers and ra-
tionals are likely to be very large in such an implementation
as the limits of this range are approached.
An implementation of Scheme must support exact integers
throughout the range of numbers that may be used for
indexes of lists, vectors, and strings or that may result
from computing the length of a list, vector, or string. The
length, vector-length, and string-length procedures
must return an exact integer, and it is an error to use
anything but an exact integer as an index. Furthermore
any integer constant within the index range, if expressed
by an exact integer syntax, will indeed be read as an exact
integer, regardless of any implementation restrictions that
may apply outside this range. Finally, the procedures listed
below will always return an exact integer result provided all
their arguments are exact integers and the mathematically
expected result is representable as an exact integer within
the implementation:
+ - *
quotient remainder modulo
max min abs
numerator denominator gcd
lcm floor ceiling
truncate round rationalize
expt
Implementations are encouraged, but not required, to sup-
port exact integers and exact rationals of practically unlim-
ited size and precision, and to implement the above proce-
dures and the / procedure in such a way that they always
return exact results when given exact arguments. If one of
these procedures is unable to deliver an exact result when
given exact arguments, then it may either report a vio-
lation of an implementation restriction or it may silently
coerce its result to an inexact number. Such a coercion
may cause an error later.
An implementation may use floating point and other ap-
proximate representation strategies for inexact numbers.
This report recommends, but does not require, that the
IEEE 32-bit and 64-bit floating point standards be followed
by implementations that use flonum representations, and
that implementations using other representations should
match or exceed the precision achievable using these float-
ing point standards [12].
In particular, implementations that use flonum represen-
tations must follow these rules: A flonum result must be
represented with at least as much precision as is used to
express any of the inexact arguments to that operation. It
is desirable (but not required) for potentially inexact oper-
ations such as sqrt, when applied to exact arguments, to
produce exact answers whenever possible (for example the
square root of an exact 4 ought to be an exact 2). If, how-
ever, an exact number is operated upon so as to produce an
inexact result (as by sqrt), and if the result is represented
as a flonum, then the most precise flonum format available
must be used; but if the result is represented in some other
way then the representation must have at least as much
precision as the most precise flonum format available.
Although Scheme allows a variety of written notations for
numbers, any particular implementation may support only
some of them. For example, an implementation in which
all numbers are real need not support the rectangular and