Open Quuxplusone opened 10 years ago
Attached bug.ll
(1527 bytes, application/octet-stream): IR file demonstrating the problem.
This also affects clang. The attached C file produces different results if
compiled with gcc-4.8.2 and clang-3.4 on Linux/x86_64.
Again, the sign bit is lost.
Attached nan.c
(293 bytes, text/plain): C file which produces different output if compiled by gcc and clang.
I think commit r187314 introduced this behavior.
Michael, I set you on CC because you are the author of this commit.
Is this really the indented functionality?
Yes that is the intended behavior and is the result of a compromise. Let me explain:
APFloat is IEEE-754 conformant (or if it violates the standard in some way, that is a bug, please file it = p).
IEEE-754 1.4 states that the interpretation of the sign and significant fields of a NaN are not specified by the standard. So one should not assume any behavior in general from a negative NaN.
Thus APFloat does not interpret/use the sign field of a NaN and for any operation that yields a NaN will only produce one form of NaN: +NaN.
On the other hand, as a compromise, if the user creates an APFloat that is a negative NaN and does not perform any operations on it we just let it through.
Does that answer your question?
Yes, it answers my question.
I am not really happy with this because
(1) gcc and clang now produce different results (at least on x86)
(2) The x86 fpu works differently
(3) as a consequence of (2), you get different results if you compile code with or without optimization. This makes debugging harder.
But I was able to fix the upstream sources. :-)
bug.ll
(1527 bytes, application/octet-stream)nan.c
(293 bytes, text/plain)