isNaN

Tests for NaN.

Function Return Value

Logical indicating whether or not A contains NaN. The output value tests .true. only if there is at least one NaN in the scalar or array. (Output)

Required Argument

A — The argument can be a scalar or array of rank-1, rank-2 or rank-3. The values can be any of the four intrinsic floating-point types. (Input)

FORTRAN 90 Interface

isNaN( A)

Description

This is a generic logical function used to test scalars or arrays for occurrence of an IEEE 754 Standard format of floating point (ANSI/IEEE 1985) NaN, or not-a-number. Either quiet or signaling NaNs are detected without an exception occurring in the test itself. The individual array entries are each examined, with bit manipulation, until the first NaN is located. For non-IEEE formats, the bit pattern tested for single precision is transfer(not(0),1). For double precision numbers x, the bit pattern tested is equivalent to assigning the integer array i(1:2) = not(0), then testing this array with the bit pattern of the integer array transfer(x,i). This function is likely to be required whenever there is the possibility that a subroutine blocked the output with NaNs in the presence of an error condition.

Example

 

use isnan_int

implicit none

 

! This is the equivalent of Example 1 for NaN.

integer, parameter :: n=3

real(kind(1e0)) A(n,n); real(kind(1d0)) B(n,n)

real(kind(1e0)), external :: s_NaN

real(kind(1d0)), external :: d_NaN

 

! Assign NaNs to both A and B:

A = s_Nan(1e0); B = d_Nan(1d0)

 

! Check that NaNs are noted in both A and B:

if (isNan(A) .and. isNan(B)) then

write (*,*) 'Example 1 for NaN is correct.'

end if

 

end