complexp
complexp Function
Syntax:
complexp object → generalized-boolean
Arguments and Values:
object—an object.
generalized-boolean—a generalized boolean.
Description:
Returns true if object is of type complex; otherwise, returns false.
Examples:
(complexp 1.2d2) → false
(complexp #c(5/3 7.2)) → true
See Also:
complex (function and type), typep
Notes:
(complexp object) ≡ (typep object ’complex)
Expanded Reference: complexp
Testing if an object is a complex number
complexp returns true if the object is of type complex.
(complexp #c(1 2))
=> T
(complexp #c(5/3 7.2))
=> T
(complexp #c(0.0 1.0))
=> T
Real numbers are not complex
Integers, ratios, and floats are not complex, even though they can be thought of as complex numbers with zero imaginary part.
(complexp 42)
=> NIL
(complexp 1.2d2)
=> NIL
(complexp 3/4)
=> NIL
Non-numeric objects
complexp returns false for all non-numeric types.
(complexp nil)
=> NIL
(complexp "complex")
=> NIL
(complexp '(1 2))
=> NIL
Complex numbers created with the complex function
The complex function creates complex numbers. If the imaginary part is an exact zero and the real part is rational, the result may be a rational rather than a complex.
(complexp (complex 1 2))
=> T
(complexp (complex 1.0 0.0))
=> T
(complexp (complex 1 0))
=> NIL
Equivalence to typep
complexp is equivalent to (typep object 'complex).
(eql (complexp #c(1 2)) (typep #c(1 2) 'complex))
=> T
(eql (complexp 42) (typep 42 'complex))
=> T