Common Lisp the Language, 2nd Edition

next up previous contents index
Next: Integers Up: Data Types Previous: Data Types

2.1. Numbers

Several kinds of numbers are defined in Common Lisp. They are divided into integers; ratios; floating-point numbers, with names provided for up to four different floating-point representations; and complex numbers.

X3J13 voted in March 1989 (REAL-NUMBER-TYPE)   to add the type real.

The number data type encompasses all kinds of numbers. For convenience, there are names for some subclasses of numbers as well. Integers and ratios are of type rational. Rational numbers and floating-point numbers are of type real. Real numbers and complex numbers are of type number.

Although the names of these types were chosen with the terminology of mathematics in mind, the correspondences are not always exact. Integers and ratios model the corresponding mathematical concepts directly. Numbers of type float may be used to approximate real numbers, both rational and irrational. The real type includes all Common Lisp numbers that represent mathematical real numbers, though there are mathematical real numbers (irrational numbers) that do not have an exact Common Lisp representation. Only real numbers may be ordered using the <, >, <=, and >= functions.

Compatibility note: The Fortran 77 standard defines the term real datum to mean ``a processor approximation to the value of a real number.'' In practice the Fortran basic real type is the floating-point data type that Common Lisp calls single-float. The Fortran double precision type is Common Lisp's double-float. The Pascal real data type is an ``implementation-defined subset of the real numbers.'' In practice this is usually a floating-point type, often what Common Lisp calls double-float.

A translation of an algorithm written in Fortran or Pascal that uses real data usually will use some appropriate precision of Common Lisp's float type. Some algorithms may gain accuracy or flexibility by using Common Lisp's rational or real type instead.


next up previous contents index
Next: Integers Up: Data Types Previous: Data Types