Chapter 12
Numbers

 12.1 Precision, Contagion, and Coercion
 12.2 Predicates on Numbers
 12.3 Comparisons on Numbers
 12.4 Arithmetic Operations
 12.5 Irrational and Transcendental Functions
  12.5.1 Exponential and Logarithmic Functions
  12.5.2 Trigonometric and Related Functions
  12.5.3 Branch Cuts, Principal Values, and Boundary Conditions in the Complex Plane
 12.6 Type Conversions and Component Extractions on Numbers
 12.7 Logical Operations on Numbers
 12.8 Byte Manipulation Functions
 12.9 Random Numbers
 12.10 Implementation Parameters

Common Lisp provides several different representations for numbers. These representations may be divided into four categories: integers, ratios, floating-point numbers, and complex numbers. Many numeric functions will accept any kind of number; they are generic. Other functions accept only certain kinds of numbers.

Note that this remark, predating the design of the Common Lisp Object System, uses the term “generic” in a generic sense and not necessarily in the technical sense used by CLOS (see chapter 2).

In general, numbers in Common Lisp are not true objects; eq cannot be counted upon to operate on them reliably. In particular, it is possible that the expression

(let ((x z) (y z)) (eq x y))

may be false rather than true if the value of z is a number. _____________

Rationale: This odd breakdown of eq in the case of numbers allows the implementor enough design freedom to produce exceptionally efficient numerical code on conventional architectures. MacLisp requires this freedom, for example, in order to produce compiled numerical code equal in speed to Fortran. Common Lisp makes this same restriction, if not for this freedom, then at least for the sake of compatibility.

___________________________________________________________________________________________________________

If two objects are to be compared for “identity,” but either might be a number, then the predicate eql is probably appropriate; if both objects are known to be numbers, then = may be preferable.