negative?, positive?, odd?, even?, flnegative?, flpositive?, flodd?, fleven?,
fxnegative?, fxpositive?, fxodd?, fxeven? - numerical predicates
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(import (rnrs arithmetic flonums)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
(negative? x)
(positive? x)
(odd? n)
(even? n)
;; R6RS
(flnegative? fl)
(flpositive? fl)
(flodd? fl)
(fleven? fl)
(fxnegative? fx)
(fxpositive? fx)
(fxodd? fx)
(fxeven? fx)
These numerical predicates test a number object for a particular property,
returning #t or #f.
- Properties tested
- The predicates tests the following properties.
| zero? |
tests if the number is = to zero |
| positive? |
tests if the number is greater than zero |
| negative? |
tests if the number is less than zero |
| odd? |
tests if the number is odd |
| even? |
tests if the number is even |
- Flonum variants
- These variants restrict their arguments to flonums.
- Fixnum variants
- These variants restrict their arguments to fixnums.
Unless the number is exact, the results may be unreliable because
a small inaccuracy may affect the result.
Returns a single value; a boolean.
(zero? +0.0) => #t
(zero? -0.0) => #t
(zero? +nan.0) => #f
(positive? +inf.0) => #t
(negative? -inf.0) => #t
(positive? +nan.0) => #f
(negative? +nan.0) => #f
These procedures work the same in all Scheme revisions since R2RS.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its
domain.
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
These procedures were first introduced in R2RS. Scheme before then, running on
MacLisp, had access to similar predicates: zerop, plusp,
minusp, and oddp. LISP 1.5 had a minusp predicate that
returned true for negative numbers, including -0. It also had zerop and
onep predicates. These were specified to true when the absolute
difference between the argument and zero or one, respectively, is less than
3e-6.