is.finite                package:base                R Documentation

Finite, Infinite and NaN Numbers

Description:

     'is.finite' and 'is.infinite' return a vector of the same length
     as 'x', indicating which elements are finite (not infinite and not
     missing).

     'Inf' and '-Inf' are positive and negative infinity whereas 'NaN'
     means 'Not a Number'.  (These apply to numeric values and real and
     imaginary parts of complex values but not to values of integer
     vectors.)  All are reserved words in the R language.

Usage:

     is.finite(x)
     is.infinite(x)
     Inf
     NaN
     is.nan(x)

Arguments:

       x: (numerical) object to be tested.

Details:

     'is.finite' returns a vector of the same length as 'x' the jth
     element of which is 'TRUE' if 'x[j]' is finite (i.e., it is not
     one of the values 'NA', 'NaN', 'Inf' or '-Inf').  All elements of
     types other than logical, integer, numeric and complex vectors are
     false.  Complex numbers are finite if both the real and imaginary
     parts are.

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

     'is.nan' tests if a numeric value is 'NaN'.  Do not test equality
     to 'NaN', or even use 'identical', since systems typically have
     many different NaN values.  One of these is used for the numeric
     missing value 'NA', and 'is.nan' is false for that value.  A
     complex number is regarded as 'NaN' if either the real or
     imaginary part is 'NaN' but not 'NA'.

     All three functions are generic: you can write methods to handle
     specific classes of objects, see InternalMethods.  The default
     methods handle real and complex vectors.

Note:

     In R, basically all mathematical functions (including basic
     'Arithmetic'), are supposed to work properly with '+/- Inf' and
     'NaN' as input or output.

     The basic rule should be that calls and relations with 'Inf's
     really are statements with a proper mathematical _limit_.

References:

     The IEC 60559 standard, also known as the ANSI/IEEE 754
     Floating-Point Standard.

     D. Goldberg (1991) _What Every Computer Scientist Should Know
     about Floating-Point Arithmetic_  ACM Computing Surveys, *23(1)*.
      Postscript 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 'isfinite' is used for 'is.finite' if available.

See Also:

     'NA', '_Not Available_' which is not a number as well, however
     usually used for missing values and applies to many modes, not
     just numeric.

Examples:

     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)

