<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>This appears to have nothing to do with signbit, but rather that we are somehow “optimizing” –NaN —> NaN.</div><div><br></div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #35568a">int</span> main(<span style="font-variant-ligatures: no-common-ligatures; color: #35568a">int</span> argc, <span style="font-variant-ligatures: no-common-ligatures; color: #35568a">char</span> *argv[]) {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a">double</span> x = -__builtin_nan(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300">""</span>);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> printf(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300">"%d\t%d\n"</span>, signbit(x));</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(53, 86, 138);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span>return<span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span>0<span style="font-variant-ligatures: no-common-ligatures; color: #000000">;</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">}</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><br></div>this prints zero on recent clang (should print 1). Stepping through, x is being set to a positive NaN.<div>– Steve</div><div><br><div><blockquote type="cite"><div>On Jun 6, 2014, at 12:21 PM, <a href="mailto:victor.zverovich@gmail.com">victor.zverovich@gmail.com</a> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr">I've checked and the same happens with the signbit macro.<div><br></div><div>Victor</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 6, 2014 at 11:56 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Jun 6, 2014 at 2:51 PM, <a href="mailto:victor.zverovich@gmail.com">victor.zverovich@gmail.com</a><br>
<<a href="mailto:victor.zverovich@gmail.com">victor.zverovich@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> When compiling with a recent version of Clang, the following code<br>
><br>
> std::signbit(-std::numeric_limits<double>::quiet_NaN())<br>
><br>
> returns true with optimizations disabled and false with optimizations<br>
> enabled. Other compilers like GCC and older versions of Clang always return<br>
> true as expected. Is it a bug or a feature?<br>
><br>
> I'm using Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn).<br>
<br>
</div></div>I believe this is likely a bug. std::signbit is defined to behave the<br>
same as the C macro of the same name, which has the footnote, "The<br>
signbit macro reports the sign of all values, including infinities,<br>
zeros, and NaNs. If zero is unsigned, it is treated as positive."<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span></blockquote></div><br></div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></div></blockquote></div><br></div></body></html>