Namespaces
Variants
Actions

Talk:cpp/numeric/math/isnan

From cppreference.com

Is NaN multiple values each having one object representation, or it's one value with multiple object representations?

see: https://en.cppreference.com/w/cpp/language/object For example, multiple floating-point bit patterns represent the same special value NaN.

[edit] Implementation-specific concerns

Would it be okay to add something about GCC and Clang's -ffinite-math-only option, as enabled by -ffast-math? One of the effects it has is to make std::isnan always return false, even for a value which is definitely NaN.

So for instance, with -ffinite-math-only, various x86-64 versions of GCC and Clang treat

 auto foo(double l_, double r_) -> bool { return std::isnan(l_/r_/r_); } 

as

 xor eax eax ret 

Obviously, this isn't an actual C++ issue per se. But it's a weird gotcha for std::isnan. Would it be fine if I added something to the Notes section like

"Many implementations include an option which allows optimizations to ignore possible NaNs, in which case std::isnan calls might be replaced with false."

?

You can definitely mention that, but you should avoid using terms like 'many implementations'. This is a reference site in the first place, so wording from sources other than WG14/21 documents should be with a reference item of the source and should not be too generalized. Take a look at the identifiers page, it references some properties in the Unicode standard, and it uses a number of external links to Unicode.org to lead the readers to the supplementary information they might want to know. --Xmcgcg (talk) 22:50, 17 July 2023 (PDT)
close