chickadee » scheme » number?

number? objprocedure
complex? objprocedure
real? objprocedure
rational? objprocedure
integer? objprocedure

These numerical type predicates can be applied to any kind of argument, including non-numbers. They return #t if the object is of the named type, and otherwise they return #f. In general, if a type predicate is true of a number then all higher type predicates are also true of that number. Consequently, if a type predicate is false of a number, then all lower type predicates are also false of that number. If z is an inexact complex number, then (real? z) is true if and only if (zero? (imag-part z)) is true. If x is an inexact real number, then (integer? x) is true if and only if (= x (round x)).

(complex? 3+4i)                 ===>  #t
(complex? 3)                    ===>  #t
(real? 3)                       ===>  #t
(real? -2.5+0.0i)               ===>  #t
(real? #e1e10)                  ===>  #t
(rational? 6/10)                ===>  #t
(rational? 6/3)                 ===>  #t
(integer? 3+0i)                 ===>  #t
(integer? 3.0)                  ===>  #t
(integer? 8/4)                  ===>  #t

Note: The behavior of these type predicates on inexact numbers is unreliable, since any inaccuracy may affect the result.

Note: In many implementations the rational? procedure will be the same as real?, and the complex? procedure will be the same as number?, but unusual implementations may be able to represent some irrational numbers exactly or may extend the number system to support some kind of non-complex numbers.