How frequently scientific code uses comparisons NaN == NaN?
Reason of asking: from time to time compilers / software floating-point library implementations have bugs w.r.t. comparisons with NaN. For instance, NaN == NaN incorrectly returns true, which is a bug.
The end user may face with this bug if the end user relies on the following logic: a != a iff (if and only if) a is NaN. Or inverse version: a == a iff a is not NaN.
However, do people really use this logic (a != a iff a is NaN) in real code? Do people use NaN == NaN comparisons in real code?
Any experience / examples are welcome!
P.S. What is the best stackexchange site to ask this question?
isnan()to check for NaNs. I don't remember what we used in the late 1980 and 1990s; I seem to recall proprietary precursors toisnan. – njuffa Jan 22 '21 at 01:21isnan-- it concisely represents the intent. – Wolfgang Bangerth Jan 22 '21 at 04:49memcmpin their application? – Federico Poloni Jan 22 '21 at 10:14NaN == NaN, but forNaN <= NaN. Using msvc C compilerprintf("%d\n", NAN <= NAN);prints 1 (instead of 0) and using msvc C++ compilerconst double nan { std::numeric_limits<double>::quiet_NaN() }; printf("%d\n", nan <= nan);prints 1 (instead of 0). – pmor Jan 22 '21 at 18:17/fp:strict? – njuffa Jan 22 '21 at 22:00/fp:strictsolvesNAN <= NANfor C, but does not solvenan <= nanfor C++. – pmor Jan 27 '21 at 21:17