\HeaderA{is.finite}{Finite, Infinite and NaN Numbers}{is.finite}
\aliasA{Inf}{is.finite}{Inf}
\aliasA{is.infinite}{is.finite}{is.infinite}
\aliasA{is.nan}{is.finite}{is.nan}
\aliasA{NaN}{is.finite}{NaN}
\keyword{programming}{is.finite}
\keyword{math}{is.finite}
\begin{Description}\relax
\code{is.finite} and \code{is.infinite} return a vector of the same
length as \code{x}, indicating which elements are finite (not infinite
and not missing).

\code{Inf} and \code{-Inf} are positive and negative \dQuote{infinity}
whereas \code{NaN} means \dQuote{Not a Number}.  (These apply to numeric
values and real and imaginary parts of complex values but not to
values of integer vectors.)
\end{Description}
\begin{Usage}
\begin{verbatim}
is.finite(x)
is.infinite(x)
Inf
NaN
is.nan(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] (numerical) object to be tested.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{is.finite} returns a vector of the same length as \code{x}
the jth element of which is \code{TRUE} if \code{x[j]} is
finite (i.e., it is not one of the values \code{NA}, \code{NaN},
\code{Inf} or \code{-Inf}).  All elements of character and
generic (list) vectors are false, so \code{is.finite} is only useful for
logical, integer, numeric and complex vectors.  Complex numbers are
finite if both the real and imaginary parts are.

\code{is.infinite} returns a vector of the same length as \code{x}
the jth element of which is \code{TRUE} if \code{x[j]} is
infinite (i.e., equal to one of \code{Inf} or \code{-Inf}). This will
be false unless \code{x} is numeric or complex.  Complex numbers are
infinite if either the real and imaginary part is.

\code{is.nan} tests if a numeric value is \code{NaN}.  Do not test
equality to \code{NaN}, or even use \code{\LinkA{identical}{identical}},
since systems typically have many different NaN values.
In most ports of \R{} one of these is used for the numeric missing
value \code{NA}.  It is generic: you can write methods to handle
specific classes of objects, see \LinkA{InternalMethods}{InternalMethods}.
\end{Details}
\begin{Note}\relax
In \R, basically all mathematical functions (including basic
\code{\LinkA{Arithmetic}{Arithmetic}}), are supposed to work properly with
\code{+/- Inf} and \code{NaN} as input or output.

The basic rule should be that calls and relations with \code{Inf}s
really are statements with a proper mathematical \emph{limit}.
\end{Note}
\begin{References}\relax
The IEC 60559 standard, also know as the
ANSI/IEEE 754 Floating-Point Standard.

D. Goldberg (1991) \emph{What Every Computer Scientist Should Know
about Floating-Point Arithmetic}  ACM Computing Surveys, \bold{23(1)}.\\
Postscript version available at
\url{http://www.validlab.com/goldberg/paper.ps}

\url{http://grouper.ieee.org/groups/754/} for accessible information.

The C99 function \code{isfinite} is used for \code{is.finite} if available.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{NA}{NA}}, \sQuote{\emph{Not Available}} which is not a number
as well, however usually used for missing values and applies to many
modes, not just numeric.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
pi / 0 ## = Inf a non-zero number divided by zero creates infinity
0 / 0  ## =  NaN

1/0 + 1/0# Inf
1/0 - 1/0# NaN

stopifnot(
    1/0 == Inf,
    1/Inf == 0
)
sin(Inf)
cos(Inf)
tan(Inf)
\end{ExampleCode}
\end{Examples}

