=, <, >, <=, >=, fl=?, fl<?, fl>?, fl<=?, fl>=?, fx=?, fx<?, fx>?, fx<=?, fx>=? - compare numbers


(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS
(import (rnrs arithmetic fixnums))  ;R6RS
(import (rnrs arithmetic flonums))  ;R6RS


(= z1 z2 z3 ...)
(< x1 x2 x3 ...)
(> x1 x2 x3 ...)
(<= x1 x2 x3 ...)
(>= x1 x2 x3 ...)
(fl=? fl1 fl2 fl3 ...)
(fl<? fl1 fl2 fl3 ...)
(fl>? fl1 fl2 fl3 ...)
(fl<=? fl1 fl2 fl3 ...)
(fl>=? fl1 fl2 fl3 ...)
(fx=? fx1 fx2 fx3 ...)
(fx<? fx1 fx2 fx3 ...)
(fx>? fx1 fx2 fx3 ...)
(fx<=? fx1 fx2 fx3 ...)
(fx>=? fx1 fx2 fx3 ...)


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

(= +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
Negative zero
IEEE 754 binary floating point numbers always have a sign bit. This also applies to NaNs and zero, so there is a negative zero. For the purpose of these predicates the negative zero is equal to zero.

(= 0.0 -0.0)  =>  #t
(< 0.0 -0.0)  =>  #f

Negative zero can be distinguished with eqv?(3scm). Implementations are not required to use IEEE 754 and are not required to support negative zero.

Inexact numbers
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?(3cm).

Quoting the Scheme reports: "When in doubt, consult a numerical analyst."

Flonum and fixnum variants
The flonum and fixnum variants of these predicates only operate on these types of objects.


The traditional implementations of these predicates in Lisp-like languages are not transitive. Quoting from R7RS:

The implementation approach of converting all arguments to inexact numbers if any argument is inexact is not transitive. For example, let big be (expt 2 1000), and assume that big is 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.


These procedures return a single value; a boolean.


(> 5 4)  =>  #t


These predicates are present in all Schemes. There are variations in which numbers are supported and what happens when they are called with bad arguments. R7RS does not require support for the whole numeric tower and R6RS does not actually require that implementations use IEEE 754, even though that is the most common implementation choice.


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.
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.


zero?(3scm), max(3scm), equal?(3scm)


R4RS, IEEE Scheme, R5RS, R6RS, R7RS


These procedures only took two arguments in R3RS and did not explicitly require them to be transitive.

R2RS specified additional redundant names ending with ?, e.g., <=? in order to "make all user populations happy".

R2RS mentions that some implementations allowed many arguments like in Common Lisp, although Scheme before R2RS that ran on MacLISP also had predicates that worked like this. MacLISP's greaterp, and lessp accepted two or more arguments. On the other hand, MacLISP also had the procedures =, >, and < that only accepted two arguments and required that the arguments are both fixnums or both flonums.

LISP 1.5 had the subroutines equal, greaterp, and lessp. The first one was the same as kind of predicate as equal?(3scm) while the latter were subroutines of two arguments that compared numbers.


This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.

Markup created by unroff 1.0sc,    March 04, 2023.