Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Characters Up: Numbers Previous: Floating-Point Numbers

2.1.4. Complex Numbers

Complex numbers (type complex) are represented in Cartesian form, with a real part and an imaginary part, each of which is a non-complex number (integer, ratio, or floating-point number). It should be emphasized that the parts of a complex number are not necessarily floating-point numbers; in this, Common Lisp is like PL/I and differs from Fortran. However, both parts must be of the same type: either both are rational, or both are of the same floating-point format.

Complex numbers may be notated by writing the characters #C followed by a list of the real and imaginary parts. If the two parts as notated are not of the same type, then they are converted according to the rules of floating-point contagion as described in chapter 12. (Indeed, #C(a b) is equivalent to #,(complex a b); see the description of the function complex.) For example:

#C(3.0s1 2.0s-1)     ;Real and imaginary parts are short format
#C(5 -3)             ;A Gaussian integer 
#C(5/3 7.0)          ;Will be converted internally to #C(1.66666 7.0) 
#C(0 1)              ;The imaginary unit, that is, i

The type of a specific complex number is indicated by a list of the word complex and the type of the components; for example, a specialized representation for complex numbers with short floating-point parts would be of type (complex short-float). The type complex encompasses all complex representations.

A complex number of type (complex rational), that is, one whose components are rational, can never have a zero imaginary part. If the result of a computation would be a complex rational with a zero imaginary part, the result is immediately converted to a non-complex rational number by taking the real part. This is called the rule of complex canonicalization. This rule does not apply to floating-point complex numbers; #C(5.0 0.0) and 5.0 are different.



next up previous contents index
Next: Characters Up: Numbers Previous: Floating-Point Numbers


AI.Repository@cs.cmu.edu