Next: , Previous: , Up: baselib math ops   [Index]


4.6.4.3 Value predicates

Procedure: = z1 z2 z3
Procedure: < x1 x2 x3
Procedure: > x1 x2 x3
Procedure: <= x1 x2 x3
Procedure: >= x1 x2 x3

These procedures return #t if their arguments are (respectively): equal, monotonically increasing, monotonically decreasing, monotonically nondecreasing, or monotonically nonincreasing, and #f otherwise.

Examples:

(= +inf.0 +inf.0)               ⇒ #t
(= -inf.0 +inf.0)               ⇒ #f
(= -inf.0 -inf.0)               ⇒ #t

for any real number object x that is neither infinite nor NaN:

(< -inf.0 x +inf.0)       ⇒ #t
(> +inf.0 x -inf.0)       ⇒ #t

for any number object z:

(= +nan.0 z)              ⇒ #f

For any real number object x:

(< +nan.0 x)              ⇒ #f
(> +nan.0 x)              ⇒ #f

These predicates must be transitive.

NOTE The traditional implementations of these predicates in Lisp–like languages are not transitive.

NOTE While it is possible to compare inexact number objects using these predicates, the results may be unreliable because a small inaccuracy may affect the result; this is especially true of = and zero? (below).

When in doubt, consult a numerical analyst.

Procedure: zero? z
Procedure: positive? x
Procedure: negative? x
Procedure: odd? n
Procedure: even? n
Procedure: finite? x
Procedure: infinite? x
Procedure: nan? x

These numerical predicates test a number object for a particular property, returning #t or #f.

zero?

Tests if the number object is = to zero.

positive?

Tests whether it is greater than zero.

negative?

Tests whether it is less than zero.

odd?

Tests whether it is odd.

even?

Tests whether it is even.

finite?

Tests whether it is not an infinity and not a NaN.

infinite?

Tests whether it is an infinity.

nan?

Tests whether it is a NaN.

(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
(finite? +inf.0)              ⇒ #f
(finite? 5)                   ⇒ #t
(finite? 5.0)                 ⇒ #t
(infinite? 5.0)               ⇒ #f
(infinite? +inf.0)            ⇒ #t

NOTE As with the predicates above, the results may be unreliable because a small inaccuracy may affect the result.


Next: , Previous: , Up: baselib math ops   [Index]