[cfe-dev] signbit returns false for negative NaN
Stephen Canon
scanon at apple.com
Fri Jun 6 12:52:56 PDT 2014
This appears to have nothing to do with signbit, but rather that we are somehow “optimizing” –NaN —> NaN.
int main(int argc, char *argv[]) {
double x = -__builtin_nan("");
printf("%d\t%d\n", signbit(x));
return 0;
}
this prints zero on recent clang (should print 1). Stepping through, x is being set to a positive NaN.
– Steve
> On Jun 6, 2014, at 12:21 PM, victor.zverovich at gmail.com wrote:
>
> I've checked and the same happens with the signbit macro.
>
> Victor
>
>
> On Fri, Jun 6, 2014 at 11:56 AM, Aaron Ballman <aaron at aaronballman.com> wrote:
> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140606/1fb0b978/attachment.html>
More information about the cfe-dev
mailing list