Rev 42961 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/is.finite.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{is.finite}\title{Finite, Infinite and NaN Numbers}\alias{is.finite}\alias{is.infinite}\alias{Inf}\alias{NaN}\alias{is.nan}\alias{finite} % for when people ask what 'finite' means.\description{\code{is.finite} and \code{is.infinite} return a vector of the samelength as \code{x}, indicating which elements are finite (not infiniteand not missing).\code{Inf} and \code{-Inf} are positive and negative infinitywhereas \code{NaN} means \sQuote{Not a Number}. (These apply to numericvalues and real and imaginary parts of complex values but not tovalues of integer vectors.) All are \code{reserved} words in the \Rlanguage.}\usage{is.finite(x)is.infinite(x)InfNaNis.nan(x)}\arguments{\item{x}{(numerical) object to be tested.}}\details{\code{is.finite} returns a vector of the same length as \code{x} thejth element of which is \code{TRUE} if \code{x[j]} is finite (i.e., itis not one of the values \code{NA}, \code{NaN}, \code{Inf} or\code{-Inf}). All elements of types other than logical, integer,numeric and complex vectors are false. Complex numbers are finite ifboth 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]} isinfinite (i.e., equal to one of \code{Inf} or \code{-Inf}). This willbe false unless \code{x} is numeric or complex. Complex numbers areinfinite if either the real and imaginary part is.\code{is.nan} tests if a numeric value is \code{NaN}. Do not testequality to \code{NaN}, or even use \code{\link{identical}}, sincesystems typically have many different NaN values. One of these is usedfor the numeric missing value \code{NA}, and \code{is.nan} is falsefor that value. A complex number is regardedas \code{NaN} if either the real or imaginary part is \code{NaN} butnot \code{NA}.All three functions are generic: you can write methods to handlespecific classes of objects, see \link{InternalMethods}. Thedefault methods handle real and complex vectors.}\note{In \R, basically all mathematical functions (including basic\code{\link{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}sreally are statements with a proper mathematical \emph{limit}.}\seealso{\code{\link{NA}}, \sQuote{\emph{Not Available}} which is not a numberas well, however usually used for missing values and applies to manymodes, not just numeric.}\references{The IEC 60559 standard, also known as theANSI/IEEE 754 Floating-Point Standard.D. Goldberg (1991) \emph{What Every Computer Scientist Should Knowabout Floating-Point Arithmetic} ACM Computing Surveys, \bold{23(1)}.\crPostscript version available at\url{http://www.validlab.com/goldberg/paper.ps}Extended PDF version at \url{http://www.validlab.com/goldberg/paper.pdf}\url{http://grouper.ieee.org/groups/754/} for accessible information.The C99 function \code{isfinite} is used for \code{is.finite} if available.}\examples{pi / 0 ## = Inf a non-zero number divided by zero creates infinity0 / 0 ## = NaN1/0 + 1/0# Inf1/0 - 1/0# NaNstopifnot(1/0 == Inf,1/Inf == 0)sin(Inf)cos(Inf)tan(Inf)}\keyword{programming}\keyword{math}