Suppose (while avoiding a night-filling discussion on why) I use -ffast-math
and my program does ten Newton iterations. They either converge or by that point a NaN will have occured.
That is what I wish to check. Now chat GPT told me that still the basic math operations will fill the bits of my number (e.g. float, double, float128, … ) with bits that express the meaning of NaN, but any attempt as to identifying that fact will fail (and I cannot get myself understanding how that would be even possible).
So suppose the program is compiled with -ffast-math
and suppose for simplicity that there is a double x in my code and I seek to know whether x is NaN. How do I do this? To me it appears I could simply implement isnan(x) by checking for x to live within limits.
I have also checked this [/questions/7263404/mingw32-stdisnan-with-ffast-math] and Chat-GPT gave me the implementation for double but all these bit-shifts may not work platform-independently and I do not want to end up going as through as having to test isnan implementations.