[cfe-dev] signbit returns false for negative NaN

Aaron Ballman aaron at aaronballman.com
Fri Jun 6 11:56:41 PDT 2014


On Fri, Jun 6, 2014 at 2:51 PM, victor.zverovich at gmail.com
<victor.zverovich at gmail.com> wrote:
> Hello,
>
> When compiling with a recent version of Clang, the following code
>
>   std::signbit(-std::numeric_limits<double>::quiet_NaN())
>
> returns true with optimizations disabled and false with optimizations
> enabled. Other compilers like GCC and older versions of Clang always return
> true as expected. Is it a bug or a feature?
>
> I'm using Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn).

I believe this is likely a bug. std::signbit is defined to behave the
same as the C macro of the same name, which has the footnote, "The
signbit macro reports the sign of all values, including infinities,
zeros, and NaNs. If zero is unsigned, it is treated as positive."

~Aaron



More information about the cfe-dev mailing list