Depending on your needs you can rely on the ieee_arithmetic module ieee_arithmetic in Fortran Wiki which already has a function for that, or you could have a read to this thread: Challenge: Testing Inf and NaN with `gfortran-13 -Ofast` for some ideas
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Checking Inf/NaN when compilers are invoked with aggressive optimization flags | 2 | 723 | September 16, 2021 | |
|
Is there a way to know if a variable is NaN, +infinity, -infinity?
|
25 | 6754 | May 31, 2022 | |
|
Challenge: Testing Inf and NaN with `gfortran-13 -Ofast`
|
38 | 1909 | October 3, 2023 | |
| Is comparison with `NaN` considered an erroneous arithmetic operation? (MWE with ifort and gfortran) | 13 | 1173 | December 20, 2022 | |
| 1/inf =? ifort says NaN | 7 | 1019 | December 9, 2022 |