[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  is.finite: 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) or
infinite.

` 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.) ` Inf ` and ` NaN ` are
[ reserved ](/link/reserved?package=base&version=3.6.2) words in the  R
language.

##  Usage

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

##  Arguments

x

R  object to be tested: the default methods handle atomic vectors.

##  Value

A logical vector of the same length as ` x ` : ` dim ` , ` dimnames ` and `
names ` attributes are preserved.

##  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 ` ) and ` FALSE ` otherwise. 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 ` ) and ` FALSE ` otherwise. This will be false unless ` x ` is numeric
or complex. Complex numbers are infinite if either the real or the imaginary
part is.

` is.nan ` tests if a numeric value is ` NaN ` . Do not test equality to ` NaN
` , or even use ` [ identical ](/link/identical?package=base&version=3.6.2) `
, 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 elements of logical, integer and raw vectors
are considered not to be NaN.

All three functions accept ` NULL ` as input and return a length zero result.
The default methods accept character and raw vectors, and return ` FALSE ` for
all entries. Prior to  R  version 2.14.0 they accepted all input, returning `
FALSE ` for most non-numeric values; cases which are not atomic vectors are
now signalled as errors.

All three functions are generic: you can write methods to handle specific
classes of objects, see [ InternalMethods
](/link/InternalMethods?package=base&version=3.6.2) .

##  References

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

[ https://en.wikipedia.org/wiki/NaN ](https://en.wikipedia.org/wiki/NaN) .

D. Goldberg (1991) _What Every Computer Scientist Should Know about Floating-
Point Arithmetic_ ACM Computing Surveys, **23(1)** . Postscript version
available at [ http://www.validlab.com/goldberg/paper.ps
](http://www.validlab.com/goldberg/paper.ps) Extended PDF version at [
http://www.validlab.com/goldberg/paper.pdf
](http://www.validlab.com/goldberg/paper.pdf)

The C99 function ` isfinite ` is used for ` is.finite ` .

##  See Also

` [ NA ](/link/NA?package=base&version=3.6.2) ` , ‘ _Not Available_ ’ which is
not a number as well, however usually used for missing values and applies to
many modes, not just numeric and complex.

` [ Arithmetic ](/link/Arithmetic?package=base&version=3.6.2) ` , ` [ double
](/link/double?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fis.finite&utm_source=r-docs&utm_medium=docs&utm_term=is.finite&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    pi / 0 ## = Inf a non-zero number divided by zero creates infinity
    0 / 0  ## =  N