http://llvm.org/bugs/show_bug.cgi?id=16666

            Bug ID: 16666
           Summary: quiet_NaN returns negative NaN
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Headers
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

std::numeric_limits<T>::quiet_NaN() sets the sign bit on the NaN value for
float and double. I expect it to clear the sign bit.

This sign bit can cause incompatibility problems for serialization of IEEE 754
floating-point numbers to binary streams (e.g. for network protocols.) I
currently use std::abs(std::numeric_limits<T>::quiet_NaN()) as a workaround.

The following program demostrates the problem (I have verified that the problem
is not in std::cout). The same program produces the correct results when
compiled with g++.

#include <limits>
#include <iostream>

int main()
{
    std::cout << std::numeric_limits<float>::quiet_NaN() << std::endl;
    std::cout << std::numeric_limits<double>::quiet_NaN() << std::endl;
    return 0;
}

PS: This bug is related to 15054, which also shows the incorrectly set sign bit
in its output.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to