max, min - find the maximum or minimum argument

LIBRARY

(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

SYNOPSIS

(max x1 x2 ...)
(fxmax fx1 fx2 ...)                 ;R6RS
(flmax fl1 fl2 ...)                 ;R6RS
(min x1 x2 ...)
(fxmin fx1 fx2 ...)                 ;R6RS
(flmin fl1 fl2 ...)                 ;R6RS

DESCRIPTION

These procedures return the maximum or minimum of their arguments.
Generic versions
For any real number object x that is not a NaN:
(max +inf.0 x)  =>  +inf.0
(min -inf.0 x)  =>  -inf.0
If any argument is inexact, then the result is also inexact (unless the procedure can prove that the inaccuracy is not large enough to affect the result, which is possible only in unusual implementations).
Fixnum versions
The arguments and the return value are fixnums. There are no special cases.
Flonum versions
The arguments are the return value are flonums. If one or more of the arguments is a NaN then a NaN is returned.

RETURN VALUES

Returns a single number object.

EXAMPLES

(max 3 4)        =>  4
(max 3.9 4)      =>  4.0

(max 42 +nan.0)  => +nan.0

COMPATIBILITY

The generic versions of these procedures work the same in all Scheme revisions.

ERRORS

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.
&implementation-restriction (R6RS)
May be raised if min or max is used to compare number objects of mixed exactness, and the numerical value of the result cannot be represented as an inexact number object without loss of accuracy.
R7RS
The reasons for &assertion described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. It is not specified how implementations should handle the &implementation-restriction case described above, but the program may be stopped.

SEE ALSO

<(3scm)

STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

HISTORY

The generic versions of these procedures are in all Scheme reports since R2RS. Early Scheme built on top of MacLISP also provided them.

The fixnum and flonum versions are new in R6RS.

AUTHORS

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

BUGS

IEEE Scheme accidentally omitted min.


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