3 ms·
> Which languages do not have a function to test for NaN? Both C and C++. > This is not unique to NaNs. There are plenty of potential floating point problems
by maximilianburke 4y ago
> Which languages do not have a function to test for NaN?
Both C and C++.
> This is not unique to NaNs. There are plenty of potential floating point problems if you enable those flags.
That's why I said in the second part that we need to do away with them.
- subharmonicon 4y agoisnan() has been around since C99.
- maximilianburke 4y agoisnan is a macro, not a function
- subharmonicon 4y agoisnan is a macro in C, function in C++. But either way, it’s an abstraction that provides a standard test for NaNs in those languages.
- BeetleB 4y agoI believe the reason he is pointing out this distinction is that if it is a macro, it can be optimized out causing bugs.
- stephencanon 4y agoNot in a sound implementation. E.g. in macOS/iOS’s libm, we replace the isnan() macro with a function call if you compile with fast-math precisely to prevent this.
- subharmonicon 4y agoSure with -fast-math or similar compiler options without a way to also say “preserve NaNs”, that could happen with macros, but it can also happen with inline functions where the body is in a header file.
- deleted 4y ago[deleted]
- BeetleB 4y ago> Both C and C++. Seems C++ only added it in C++11. Surprising. > That's why I said in the second part that we need to do away with them. Do away entirely with fast math calculations? That would be horrible. They exist for a very good reason: Some applications are too slow without them. Enabling subnormal numbers can really slow things down. I'd wager that for the majority of programs written, the fast math is as good as the accurate math.
- maximilianburke 4y ago> I'd wager that for the majority of programs written, the fast math is as good as the accurate math. I'd take that wager. I spent 13 years working on video games and video game technology, a domain where floating point performance is critical, and by and large we never used fast-math because of the problems it created for us.
- BeetleB 4y agoHappy to take that wager, because the majority of programs written are not video games related :-)
- gautamcgoel 4y agoThis is surprising to me! Can you explain what problems you encountered? My (limited) understanding is that the main effect of fast-math is to turn off support for subnormals. Since subnormals are only used to represent extremely small values, I wouldn't expect them to have much effect in the real world.
- subharmonicon 4y agofast-math can result in many things you may not expect, e.g. treating FP operations as being associative and distributive, which they aren’t.
- Dylan16807 4y agoSure but when does that matter in video game math?
- stephencanon 4y agoC has had isnan() for over two decades. It’s technically a macro, but that doesn’t matter for this use case.