Hacker News new | ask | show | jobs
by subharmonicon 1256 days ago
isnan() has been around since C99.
1 comments

isnan is a macro, not a function
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.
I believe the reason he is pointing out this distinction is that if it is a macro, it can be optimized out causing bugs.
Sure 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.
Not 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.