[cfe-dev] signbit returns false for negative NaN
Chandler Carruth
chandlerc at google.com
Fri Jun 6 13:02:20 PDT 2014
On Fri, Jun 6, 2014 at 12:52 PM, Stephen Canon <scanon at apple.com> wrote:
> 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.
The standards for C and C++, and consequentially Clang and LLVM, are
terribly underspecified w.r.t. things like NaN behavior. =/ We have seen
this before, and even if we fix it in Clang/LLVM I worry that it will
regress as there are many places where we model NaNs in a manner slightly
too aggressive to be strictly IEEE-754 conforming. =[
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140606/7d499235/attachment.html>
More information about the cfe-dev
mailing list