= -- r7rs Definition comparator;
Procedure variants:
((number-not-nan |2...|) -> (boolean))
number-not-nan;... -- at least 2 times;boolean;((number |2...|) -> (false))
scheme:base -- (scheme base);scheme -- (scheme);(= z_1 z_2 z_3 ...) (< x_1 x_2 x_3 ...) (> x_1 x_2 x_3 ...) (<= x_1 x_2 x_3 ...) (>= x_1 x_2 x_3 ...)These procedures return
#tif their arguments are (respectively): equal, monotonically increasing, monotonically decreasing, monotonically non-decreasing, or monotonically non-increasing, and#fotherwise. If any of the arguments are+nan.0, all the predicates return#f. They do not distinguish between inexact zero and inexact negative zero.These predicates are required to be transitive.
Note: The implementation approach of converting all arguments to inexact numbers if any argument is inexact is not transitive. For example, let
bigbe(expt 2 1000), and assume thatbigis exact and that inexact numbers are represented by 64-bit IEEE binary floating point numbers. Then(= (- big 1) (inexact big))and(= (inexact big) (+ big 1))would both be true with this approach, because of the limitations of IEEE representations of large integers, whereas(= (- big 1) (+ big 1))is false. Converting inexact values to exact numbers that are the same (in the sense of=) to them will avoid this problem, though special care must be taken with infinities.Note: While it is not an error to compare inexact numbers using these predicates, the results are unreliable because a small inaccuracy can affect the result; this is especially true of
=andzero?. When in doubt, consult a numerical analyst.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.