PDA

View Full Version : Testing for Inf and NaN values.


R. T. (Fortran Man)
09-08-2003, 05:15 PM
How can I test to see if a variable contains an IEEE Inf or NaN value? Using the "==" or ".eq." operator in an IF statement does not work.

Lahey Support
09-08-2003, 06:09 PM
Because the IEEE values Inf and NaN are not considered to be floating point numbers, they cannot be used in logical numeric comparisons. What is required is a bit by bit comparison of the value being tested.
Attached is a Fortran module which contains a series of elemental functions to test fot Inf and NaN values. These functions may accept either scalar or array arguments and return a scalar or array logical result. If the result is true, that means the value is an Inf or NaN value.