Regards to all, and best wishes.
ian
Le 05/01/2021 à 10:27, Vincent Lefevre a écrit :
On 2021-01-04 04:59:28 +0100, Michael Matz wrote:
Hello,
On Mon, 4 Jan 2021, Vincent Lefevre wrote:
-----------------------------
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
double d = strtod("-nan", NULL);
d = -d;
printf("%g, signbit(d) = %d\n", d, signbit(d));
return 0;
}
-----------------------------
Results:
$ gcc foo.c -o foo && ./foo
-nan, signbit(d) = 1
$ tcc foo.c -o foo2 && ./foo2
nan, signbit(d) = 0
I get the same results as gcc with clang and pcc. tcc is the outlier.
AFAIK, the status of the sign bit of a NaN is unspecified, except
for some particular functions, but not strtod. So I don't see a
bug in tcc.
Note: for GCC, there's an inconsistency between your testcase
and the result.
Yeah, I think that's merely a typo in Arnolds email. The inconsistency is
there, applying unary '-' to a NaN doesn't change the sign of it in TCC.
But my point is that with the above testcase, you cannot know whether
the difference between gcc and tcc comes from strtod (which would be
valid, as strtod doesn't specify the sign or NaN) or the "d = -d;"
(which would be invalid). A printf should have been added between
the strtod and the "d = -d;" to be sure.
--
-- sibian0218@gmail.com
-- Développeur compulsif