ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_except::isNAN Interface Reference

Generate and return .true. if the input value is an IEEE-compliant NAN (Not a Number) or if the input value x is not equal to its input copy xcopy, a characteristic behavior of NAN values.
More...

Detailed Description

Generate and return .true. if the input value is an IEEE-compliant NAN (Not a Number) or if the input value x is not equal to its input copy xcopy, a characteristic behavior of NAN values.

If the input value is a complex number, then the output is .true. if any of the real or imaginary components or both components are NaN.

Parameters
[in]x: The input scalar or array of the same rank as other input array-like arguments of either
  1. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  2. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
whose value will be tested for being NaN.
[in]xcopy: The input scalar or array of the same rank as other input array-like arguments, of the same type and kind and value as the input argument x.
  1. When xcopy is missing, the procedure relies on IEEE-compliant intrinsic routines for detecting NaN.
  2. When xcopy is present, its value is directly compared with the input x for non-equality to detect NaN.
(optional. If missing, IEEE-compliance is assumed for detecting NaN.)
Returns
isNotANumber : The output scalar or array of the same shape as the input x of type logical of default kind LK whose value is .true. if the input x is NaN, otherwise it is .false..


Possible calling interfaces

use pm_kind, only: LK
use pm_except, only: isNAN
logical(LK) :: isNotANumber
isNotANumber = isNAN(x)
isNotANumber = isNAN(x, xcopy)
Generate and return .true. if the input value is an IEEE-compliant NAN (Not a Number) or if the input...
Definition: pm_except.F90:2103
This module contains procedures and generic interfaces for testing for exceptional cases at runtime.
Definition: pm_except.F90:46
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
Warning
Keep in mind that NaN might not even be defined for non-IEEE-compliant compilers or when certain aggressive IEEE-breaking optimization flags are specified like -O3 -ffast-math with GNU gfortran or -fast with Intel ifort compilers.
In such cases, this algorithm with only one input argument which relies on IEEE-compliance may spectacularly fail.
After all, why would one need NaN in fast mode?
The two-arguments interface relies on the observation that NaN is the only value that is not equal to itself.
This approach to detecting NaN works as long as the compiler does not perform aggressive optimizations to inline the NaN-detection procedure, thereby allowing to eliminate the direct comparison of x with itself through aggressive optimizations.
As such, the procedures under the two-arguments interface are declared impure to present inlining of the procedures.
Remarks
The procedures of this generic interface are pure with one input argument and impure with two input arguments.
The procedures under discussion are elemental.
Note
According to the IEEE definition, if a real variable x is NaN then x /= x always yields .true..
This can be simple fast test of NaN when the processor is IEEE-compliant.
However, keep in mind that some compilers might optimize such comparison away.
The procedures under this generic interface with single input argument x use ieee_is_nan(x) from the ieee_arithmetic intrinsic module to detect NaN values.
This generic interface extends this function also to complex numbers.
Note that the Intel and GNU Fortran compilers also have the isnan(x) extension function.
See also
isInf
isNAN
getNAN
setNAN
isInfPos
isInfNeg
getInfPos
setInfPos
getInfNeg
setInfNeg


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_kind, only: RKS, RKD, RKH ! all processor types and kinds are supported.
5 use pm_kind, only: CKS, CKD, CKH ! all processor types and kinds are supported.
6 use pm_io, only: display_type
7 use pm_except, only: isNAN, setNAN
8
9 implicit none
10
11 real(RKH) :: X_RKH(3)
12 real(RKD) :: X_RKD(3)
13 real(RKS) :: X_RKS(3)
14 complex(CKH) :: X_CKH(3)
15 complex(CKD) :: X_CKD(3)
16 complex(CKS) :: X_CKS(3)
17
18 type(display_type) :: disp
19 disp = display_type(file = "main.out.F90")
20
21 call setNAN(X_RKH)
22 call setNAN(X_RKD)
23 call setNAN(X_RKS)
24
25 call setNAN(X_CKH)
26 call setNAN(X_CKD)
27 call setNAN(X_CKS)
28
29 X_RKH(2) = 0._RKH
30 X_RKD(2) = 0._RKD
31 X_RKS(2) = 0._RKS
32
33 X_CKH(2) = (0._CKH, 0._CKH)
34 X_CKD(2) = (0._CKD, 0._CKD)
35 X_CKS(2) = (0._CKS, 0._CKS)
36
37 X_CKH(2) = cmplx(0._CKH, X_RKH(1), CKH)
38 X_CKD(2) = cmplx(X_RKD(1), 0._CKD, CKD)
39 X_CKS(2) = cmplx(0._CKS, 0._CKS, CKS)
40
41 call disp%skip
42 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
43 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
44 call disp%show("!Generate real IEEE-compliant NaN.")
45 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
46 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
47 call disp%skip
48
49 call disp%skip
50 call disp%show("!%%%%%%%%%%%")
51 call disp%show("!32-bit real")
52 call disp%show("!%%%%%%%%%%%")
53 call disp%skip
54
55 call disp%skip
56 call disp%show("X_RKS(1)")
57 call disp%show( X_RKS(1) )
58 call disp%show("isNAN(X_RKS(1))")
59 call disp%show( isNAN(X_RKS(1)) )
60 call disp%skip
61
62 call disp%skip
63 call disp%show("X_RKS")
64 call disp%show( X_RKS )
65 call disp%show("isNAN(X_RKS)")
66 call disp%show( isNAN(X_RKS) )
67 call disp%skip
68
69 call disp%skip
70 call disp%show("!%%%%%%%%%%%")
71 call disp%show("!64-bit real")
72 call disp%show("!%%%%%%%%%%%")
73 call disp%skip
74
75 call disp%skip
76 call disp%show("X_RKD(1)")
77 call disp%show( X_RKD(1) )
78 call disp%show("isNAN(X_RKD(1))")
79 call disp%show( isNAN(X_RKD(1)) )
80 call disp%skip
81
82 call disp%skip
83 call disp%show("X_RKD")
84 call disp%show( X_RKD)
85 call disp%show("isNAN(X_RKD)")
86 call disp%show( isNAN(X_RKD) )
87 call disp%skip
88
89 call disp%skip
90 call disp%show("!%%%%%%%%%%%%")
91 call disp%show("!128-bit real")
92 call disp%show("!%%%%%%%%%%%%")
93 call disp%skip
94
95 call disp%skip
96 call disp%show("X_RKH(1)")
97 call disp%show( X_RKH(1) )
98 call disp%show("isNAN(X_RKH(1))")
99 call disp%show( isNAN(X_RKH(1)) )
100 call disp%skip
101
102 call disp%skip
103 call disp%show("X_RKH")
104 call disp%show( X_RKH )
105 call disp%show("isNAN(X_RKH)")
106 call disp%show( isNAN(X_RKH) )
107 call disp%skip
108
109
110 call disp%skip
111 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
112 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
113 call disp%show("!Generate complex IEEE-compliant NaN.")
114 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
115 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
116 call disp%skip
117
118
119 call disp%skip
120 call disp%show("!%%%%%%%%%%%%%%")
121 call disp%show("!32-bit complex")
122 call disp%show("!%%%%%%%%%%%%%%")
123 call disp%skip
124
125 call disp%skip
126 call disp%show("X_CKS(1)")
127 call disp%show( X_CKS(1) )
128 call disp%show("isNAN(X_CKS(1))")
129 call disp%show( isNAN(X_CKS(1)) )
130 call disp%skip
131
132 call disp%skip
133 call disp%show("X_CKS")
134 call disp%show( X_CKS )
135 call disp%show("isNAN(X_CKS)")
136 call disp%show( isNAN(X_CKS) )
137 call disp%skip
138
139 call disp%skip
140 call disp%show("!%%%%%%%%%%%%%%")
141 call disp%show("!64-bit complex")
142 call disp%show("!%%%%%%%%%%%%%%")
143 call disp%skip
144
145 call disp%skip
146 call disp%show("X_CKD(1)")
147 call disp%show( X_CKD(1) )
148 call disp%show("isNAN(X_CKD(1))")
149 call disp%show( isNAN(X_CKD(1)) )
150 call disp%skip
151
152 call disp%skip
153 call disp%show("X_CKD")
154 call disp%show( X_CKD )
155 call disp%show("isNAN(X_CKD)")
156 call disp%show( isNAN(X_CKD) )
157 call disp%skip
158
159 call disp%skip
160 call disp%show("!%%%%%%%%%%%%%%%")
161 call disp%show("!128-bit complex")
162 call disp%show("!%%%%%%%%%%%%%%%")
163 call disp%skip
164
165 call disp%skip
166 call disp%show("X_CKH(1)")
167 call disp%show( X_CKH(1) )
168 call disp%show("isNAN(X_CKH(1))")
169 call disp%show( isNAN(X_CKH(1)) )
170 call disp%skip
171
172 call disp%skip
173 call disp%show("X_CKH")
174 call disp%show( X_CKH )
175 call disp%show("isNAN(X_CKH)")
176 call disp%show( isNAN(X_CKH) )
177 call disp%skip
178
179end program example
Return an IEEE-compliant quiet NAN (Not a Number).
Definition: pm_except.F90:2593
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter CKH
The scalar integer constant of intrinsic default kind, representing the highest-precision complex kin...
Definition: pm_kind.F90:843
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter CKD
The double precision complex kind in Fortran mode. On most platforms, this is a 64-bit real kind.
Definition: pm_kind.F90:571
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4!Generate real IEEE-compliant NaN.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%
10!32-bit real
11!%%%%%%%%%%%
12
13
14X_RKS(1)
15NaN
16isNAN(X_RKS(1))
17T
18
19
20X_RKS
21NaN, +0.00000000, NaN
22isNAN(X_RKS)
23T, F, T
24
25
26!%%%%%%%%%%%
27!64-bit real
28!%%%%%%%%%%%
29
30
31X_RKD(1)
32NaN
33isNAN(X_RKD(1))
34T
35
36
37X_RKD
38NaN, +0.0000000000000000, NaN
39isNAN(X_RKD)
40T, F, T
41
42
43!%%%%%%%%%%%%
44!128-bit real
45!%%%%%%%%%%%%
46
47
48X_RKH(1)
49NaN
50isNAN(X_RKH(1))
51T
52
53
54X_RKH
55NaN, +0.00000000000000000000000000000000000, NaN
56isNAN(X_RKH)
57T, F, T
58
59
60!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62!Generate complex IEEE-compliant NaN.
63!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
66
67!%%%%%%%%%%%%%%
68!32-bit complex
69!%%%%%%%%%%%%%%
70
71
72X_CKS(1)
73(NaN, NaN)
74isNAN(X_CKS(1))
75T
76
77
78X_CKS
79(NaN, NaN), (+0.00000000, +0.00000000), (NaN, NaN)
80isNAN(X_CKS)
81T, F, T
82
83
84!%%%%%%%%%%%%%%
85!64-bit complex
86!%%%%%%%%%%%%%%
87
88
89X_CKD(1)
90(NaN, NaN)
91isNAN(X_CKD(1))
92T
93
94
95X_CKD
96(NaN, NaN), (NaN, +0.0000000000000000), (NaN, NaN)
97isNAN(X_CKD)
98T, T, T
99
100
101!%%%%%%%%%%%%%%%
102!128-bit complex
103!%%%%%%%%%%%%%%%
104
105
106X_CKH(1)
107(NaN, NaN)
108isNAN(X_CKH(1))
109T
110
111
112X_CKH
113(NaN, NaN), (+0.00000000000000000000000000000000000, NaN), (NaN, NaN)
114isNAN(X_CKH)
115T, T, T
116
117
Test:
test_pm_except
Todo:
Critical Priority: The implementation of the test for NaN should be improved to a bitwise comparison that is also valid with non-IEEE-compliant processors.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Friday 1:54 AM, April 21, 2017, Institute for Computational Engineering and Sciences (ICES), The University of Texas, Austin, TX

Definition at line 2103 of file pm_except.F90.


The documentation for this interface was generated from the following file: