3 ms·
isnan 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.
by subharmonicon 4y ago
isnan 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.