IDL

FINITE

FINITE

The FINITE function identifies whether or not a given argument is finite.

Examples


Example 1

To find out if the logarithm of 5.0 is finite, enter:

PRINT, FINITE(ALOG(5.0))

IDL prints “1” because the argument is finite.

See Additional Examples for more examples of using FINITE.

Syntax


Result = FINITE( X [, /INFINITY] [, /NAN] [, SIGN=value])

Return Value


Returns 1 (True) if its argument is finite. If the argument is infinite or not a defined number (NaN), the FINITE function returns 0 (False). The result is a byte expression of the same structure as the argument X.

Arguments


X

A floating-point, double-precision, or complex scalar or array expression. Strings are first converted to floating-point. This function is meaningless for byte, integer, or longword arguments.

Keywords


INFINITY

Set this keyword to cause FINITE to return True if the X argument is the IEEE special floating-point value Infinity (either positive or negative), or False otherwise.

NAN

Set this keyword to cause FINITE to return True if the X argument is the IEEE special floating-point value “Not A Number” (NaN), or False otherwise.

SIGN

If the INFINITY or NAN keyword is set, then set this keyword to one of the following values:

 

Value

Description

> 0

If the INFINITY keyword is set, return True (1) if X is positive infinity, False (0) otherwise. If the NAN keyword is set, return True (1) if X is +NaN (negative sign bit is not set), False (0) otherwise.

0 (the default)

The sign of X (positive or negative) is ignored.

< 0

If the INFINITY is set, return True (1) if X is negative infinity, False (0) otherwise. If the NAN keyword is set, return True (1) if X is -NaN (negative sign bit is set), False (0) otherwise.

If neither the INFINITY nor NAN keyword is set, then this keyword is ignored.

Thread Pool Keywords

This routine is written to make use of IDL’s thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the !CPU system variable control whether IDL uses the thread pool for a given computation. In addition, you can use the thread pool keywords TPOOL_MAX_ELTS, TPOOL_MIN_ELTS, and TPOOL_NOTHREAD to override the defaults established by !CPU for a single invocation of this routine. See Thread Pool Keywords for details.

Additional Examples


Example 2

To determine which elements of an array are infinity or NaN (Not a Number) values:

A = FLTARR(10)
; Set some values to +/-NaN and positive or negative Infinity:
A[3] = !VALUES.F_NAN
A[4] = -!VALUES.F_NAN
A[6] = !VALUES.F_INFINITY
A[7] = -!VALUES.F_INFINITY

Find the location of values in A that are positive or negative Infinity:

PRINT, WHERE(FINITE(A, /INFINITY))

IDL prints:

            6           7

Find the location of values in A that are NaN:

PRINT, WHERE(FINITE(A, /NAN))

IDL prints:

            3           4

Find the location of values in A that are negative Infinity:

PRINT, WHERE(FINITE(A, /INFINITY, SIGN=-1))

IDL prints:

            7

Find the location of values in A that are +NaN:

PRINT, WHERE(FINITE(A, /NAN, SIGN=1))

IDL prints:

            3
 

Note: On some platforms, there is no distinction between +NaN and -NaN.

Version History


Original

Introduced

See Also


CHECK_MATH, MACHAR, !VALUES

Notes


TS
Sometimes it's useful to find the indexes of NaNs and Infs in an array at the same time instead of searching for either exception. Use ~finite() to do so:

Example:
a = [1,-!values.f_infinity,3,4,!values.f_nan,6,7,8,!values.f_infinity,10,11,-!values.f_nan]
print,where(~finite(a))

IDL prints:
1 4 8 11
30th September 2014 4:01am


This information is not subject to the controls of the International Traffic in Arms Regulations (ITAR) or the Export Administration Regulations (EAR). However, it may be restricted from transfer to various embargoed countries under U.S. laws and regulations.
© 2014 Exelis Visual Information Solutions