Previous: Random Numbers, Up: Numbers

8.4 Implementation Parameters

This package defines several useful constants having to do with floating-point numbers.

It determines their values by exercising the computer's floating-point arithmetic in various ways. Because this operation might be slow, the code for initializing them is kept in a separate function that must be called before the parameters can be used.

— Function: cl-float-limits

This function makes sure that the Common Lisp floating-point parameters like cl-most-positive-float have been initialized. Until it is called, these parameters will be nil. If the parameters have already been initialized, the function returns immediately.

The algorithm makes assumptions that will be valid for almost all machines, but will fail if the machine's arithmetic is extremely unusual, e.g., decimal.

Since true Common Lisp supports up to four different kinds of floating-point numbers, it has families of constants like most-positive-single-float, most-positive-double-float, most-positive-long-float, and so on. Emacs has only one kind of floating-point number, so this package just uses single constants.

— Variable: cl-most-positive-float

This constant equals the largest value a Lisp float can hold. For those systems whose arithmetic supports infinities, this is the largest finite value. For IEEE machines, the value is approximately 1.79e+308.

— Variable: cl-most-negative-float

This constant equals the most negative value a Lisp float can hold. (It is assumed to be equal to (- cl-most-positive-float).)

— Variable: cl-least-positive-float

This constant equals the smallest Lisp float value greater than zero. For IEEE machines, it is about 4.94e-324 if denormals are supported or 2.22e-308 if not.

— Variable: cl-least-positive-normalized-float

This constant equals the smallest normalized Lisp float greater than zero, i.e., the smallest value for which IEEE denormalization will not result in a loss of precision. For IEEE machines, this value is about 2.22e-308. For machines that do not support the concept of denormalization and gradual underflow, this constant will always equal cl-least-positive-float.

— Variable: cl-least-negative-float

This constant is the negative counterpart of cl-least-positive-float.

— Variable: cl-least-negative-normalized-float

This constant is the negative counterpart of cl-least-positive-normalized-float.

— Variable: cl-float-epsilon

This constant is the smallest positive Lisp float that can be added to 1.0 to produce a distinct value. Adding a smaller number to 1.0 will yield 1.0 again due to roundoff. For IEEE machines, epsilon is about 2.22e-16.

— Variable: cl-float-negative-epsilon

This is the smallest positive value that can be subtracted from 1.0 to produce a distinct value. For IEEE machines, it is about 1.11e-16.