Rational Numbers in Scheme
It is
very important to be careful about specifying non-integer numbers in Scheme.
In the teaching language, most people get used to representing rational numbers in “decimal notation”;
that is, in a fashion such that
1.1
and
11/10
both refer to exactly the same number.
In the module language, this is not the case.
Any number specified in “decimal notation” will be interpreted as an inexact
number (floating point), which is no longer an exact representation of the value and is
subject to a host of problems that come from truncation. This means that
1.1
and
11/10
are no longer the same, and will not be compared as such if passed to
equal?
;
the first is an inexact number, but the second is an exactly specified rational.
This means that great care must be taken not to specify any “decimal notation”
as a general rule
(for example, in any
options.ss
files or in any
BitterSuiteScheme modules)
unless an inexact number is actually desired.
It is almost always the case that any non-integer numbers should be expressed in a rational fashion.
Is this page incorrect?
I believe this issue should be fixed now because of a change to the settings of the Scheme reader. Somebody please confirm if this is the case and adjust this page accordingly...
--
TerryVaskor - 12 Nov 2010