Is x!=x legal way to implement std::isnan()

Although Microsoft blogs claim otherwise using std::isnan in my code still does generate calls to c++ runtime instead of inlined ucomiss. Now I worked around that with x!=x check(since perf matters to me in this piece of code), but that made me wonder... If x!=x is a way to check for NaNess would that not be an easy way to implement std::isnan?

But from what I know gcc/clang use intrinsics (and msvc is trying). Why would they bother if it can be efficiently implemented as a normal function?

So I am a bit confused since one of the answers on SO claims that it is the only way selfcomparison can return false.



Read more here: https://stackoverflow.com/questions/65723923/is-x-x-legal-way-to-implement-stdisnan

Content Attribution

This content was originally published by NoSenseEtAl at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: