number? -- r7rs Definition type-predicate;
Procedure variants:
((integer) -> (true))
((rational) -> (true))
((real) -> (true))
((complex) -> (true))
((number) -> (true))
((any) -> (false))
scheme:base -- (scheme base);scheme -- (scheme);(number? obj) (complex? obj) (real? obj) (rational? obj) (integer? obj)These numerical type predicates can be applied to any kind of argument, including non-numbers. They return
#tif 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
zis a complex number, then(real? z)is true if and only if(zero? (imag-part z))is true. Ifxis an inexact real number, then(integer? x)is true if and only if(= x (round x)).The numbers
+inf.0,-inf.0, and+nan.0are real but not rational.(complex? 3+4i) ===> #t (complex? 3) ===> #t (real? 3) ===> #t (real? -2.5+0i) ===> #t (real? -2.5+0.0i) ===> #f (real? #e1e10) ===> #t (real? +inf.0) ===> #t (real? +nan.0) ===> #t (rational? -inf.0) ===> #f (rational? 3.5) ===> #t (rational? 6/10) ===> #t (rational? 6/3) ===> #t (integer? 3+0i) ===> #t (integer? 3.0) ===> #t (integer? 8/4) ===> #tNote: The behavior of these type predicates on inexact numbers is unreliable, since any inaccuracy might affect the result.
Note: In many implementations the
complex?procedure will be the same asnumber?, but unusual implementations may represent some irrational numbers exactly or may extend the number system to support some kind of non-complex numbers.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.