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

bignums are bogus



(Time to get out the asbestos suit -- I'm sure this is going to generate
a lot of flamage....)

Quoting from CLtL (p 13):  "Common Lisp in principle imposes no limit on
the magnitude of an integer; storage is automatically allocated as
necessary to represent large integers."

This is the only statement I can find on the subject of how large integers
can be in CL.  I think we can probably all agree that every implementation
does impose *some* limit on the size of integers; I don't know of any machine
that has an infinitely large amount of memory, or even an infinitely large
address space.  I expect some implementations of bignums have other
constraints as well:  assuming the number of bigits is a fixnum, storing
the bigits in an array (limiting the number of bigits to the maximum array
size), or similar representation-related problems.

Three questions:

(1) What is supposed to happen if the user attempts to create an integer 
larger than the implementation can support?  An easy way to do this would 
be to make several layers of calls to "ash":

    (let ((huge  most-positive-fixnum))
         (dotimes (i most-positive-fixnum)
             (setq huge (+ huge (ash huge huge))))
         huge)
        

(2) If "it is an error" to create a bignum larger than the implementation
can handle, how can user programs detect and avoid this situation?  If the
constraint is in the representation, having a constant to indicate the
maximum number of bits is a possibility, but if the problem is running out
of memory, it wouldn't be of much use.

(3) Given that every implementation has some practical limit on the size of
integers, but CLtL leaves that limit unspecified, is there any reason why
an implementation couldn't choose to make that limit fairly small, like 32
or 64 bits or whatever the largest machine integer size is?  (I realize 
that doing so might break the Universal Time functions, but I've already
noted that it's fairly easy to break other built-in functions as well,
regardless of how big integers can be.)  For that matter, what if the
maximum size of an integer just happened to be the maximum size of a fixnum?

-Sandra
-------