[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why is there no REAL number data type?



The term "Real Number" has a very precise meaning mathematically, and
the designers of Common Lisp are right not to abuse it, as has been
done in some other languages.  Remember that, where numerical
computation is concerned, computers are *finite* state machines, and
so they cannot represent any real numbers which are not rational, at
least not in any format which can be reconciled with rationals for
computation.  So for purposes of numerical computation, we are limited
to a subset of the reals, the rationals, and it is right to call them
that.  For some rationals it is convenient to represent them as
terminating, floating-point "decimals", which come close enough to
reals for most needs.  Thus we always use 3.14159 or 22/7 for the real
number pi.

When this is not good enough, programs like MACSYMA to do what we
humans do by hand, i.e. do algebra with symbols to represent reals
like pi until they are forced to do numerical computation, at which
point they substitute 3.14159 for the symbol "pi".

If this still bothers you, look at it this way: we cannot represent
all the integers as fixnums (although we do a good practical imitation
using bignums).  We can only represent fixnums which fit in a certain
range (and bignums must fit in available memory).  We simply cannot
represent integers that are arbitrarily positive or arbitrarily
negative without resorting to the trick in the above paragraph.
Likewise we cannot represent all the reals, because we do not have
infinite precision on our floats-- the "decimals" must terminate
before we run out of addressable memory.  In practice we limit them
to a certain size, like 32 bits.


Now, can anyone tell me why Common Lisp floating-point numbers are not considered a
subset of rationals?  I find that 

(rationalp 22/7) => t

and

(rationalp 22)   => t

but 

(rationalp 22.7) => nil
                            ______
                            HUNTER