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
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
-
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 .
-
When
xcopy is missing, the procedure relies on IEEE-compliant intrinsic routines for detecting NaN .
-
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 ⛓
logical(LK) :: isNotANumber
isNotANumber
= isNAN(x, xcopy)
Generate and return .true. if the input value is an IEEE-compliant NAN (Not a Number) or if the input...
This module contains procedures and generic interfaces for testing for exceptional cases at runtime.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
- 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.
- 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 ⛓
14 complex(CKH) :: X_CKH(
3)
15 complex(CKD) :: X_CKD(
3)
16 complex(CKS) :: X_CKS(
3)
18 type(display_type) :: disp
33 X_CKH(
2)
= (
0._CKH,
0._CKH)
34 X_CKD(
2)
= (
0._CKD,
0._CKD)
35 X_CKS(
2)
= (
0._CKS,
0._CKS)
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)
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(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
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(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
Return an IEEE-compliant quiet NAN (Not a Number).
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
integer, parameter CKH
The scalar integer constant of intrinsic default kind, representing the highest-precision complex kin...
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter CKD
The double precision complex kind in Fortran mode. On most platforms, this is a 64-bit real kind.
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
38NaN,
+0.0000000000000000, NaN
55NaN,
+0.00000000000000000000000000000000000, NaN
79(NaN, NaN), (
+0.00000000,
+0.00000000), (NaN, NaN)
96(NaN, NaN), (NaN,
+0.0000000000000000), (NaN, NaN)
113(NaN, NaN), (
+0.00000000000000000000000000000000000, NaN), (NaN, NaN)
- 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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- 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.