finite?, infinite?, nan?  floatingpoint classification procedures
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme inexact)) ;R7RS
(import (rnrs arithmetic flonums)) ;R6RS
SYNOPSIS
;; R6RS
(finite? x)
(infinite? x)
(nan? x)
(flfinite? fl)
(flinfinite? fl)
(flnan? fl)
;; R7RS
(finite? z)
(infinite? z)
(nan? z)
DESCRIPTION
These numerical predicates test a number object for a particular
property, returning
#t
or
#f.
 finite?

Tests whether
x
is not an infinity and not a NaN.
 infinite?

Tests whether
x
is an infinity.
 nan?

Tests whether
x
is a NaN.
The R7RS variants are extended to support complex numbers (if the
implementation supports complex numbers).
 finite?

Tests whether the real and imaginary parts of
z
are finite.
 infinite?

Tests whether the real or imaginary parts of
z
are infinite.
 nan?

Tests whether the real or imaginary parts of
z
are NaN.
The flonum variants in R6RS are restricted to flonum arguments.
The results may be unreliable because a small inaccuracy may affect
the result.
RETURN VALUES
These procedures return a single value; a boolean object.
EXAMPLES
(finite? +inf.0) => #f
(finite? 5) => #t
(finite? 5.0) => #t
(infinite? 5.0) => #f
(infinite? +inf.0) => #t
(nan? 32) => #f
;; R7RS examples
(finite? +inf.0) => #f
(finite? 3.0+inf.0i) => #f
(infinite? +inf.0) => #t
(infinite? +nan.0) => #f
(infinite? 3.0+inf.0i) => #t
(nan? +nan.0) => #t
(nan? +nan.0+5.0i) => #t
(nan? 1+2i) => #f
APPLICATION USAGE
A common use for the
nan?
procedure is to replace NaNs with some another value, such as zero.
It's not possible to check for NaNs with code like
(= x +nan.0).
COMPATIBILITY
The variants in R6RS only support real numbers.
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.
In particular, the flonum variants require a flonum argument.
 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.
SEE ALSO
zero?(3scm)
STANDARDS
R6RS,
R7RS
HISTORY
These procedures are new in R6RS and were later also added in R7RS
with names that coincide with those in R6RS.
The C99 language and POSIX offer a more detailed classification which
includes subnormals, see
fpclassify(3).
AUTHORS
This page is part of the
schememanpages
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.