Hello,
On Wed, 6 Jan 2021, ian wrote:
Hi to all, and happy new year.
AFAIK neither -NaN nor +NaN have sense (how to put a sign at a 'not a
number' ????).
To be precise, the sense isn't specified. Like for the payload of IEEE
NaNs you can give it any meaning you like, including none. But if you
regard unary minus as a non-arithmetic but algebraic operation (like
recommended by IEEE) on an extension of the float numbers, it should do
something to the (algebraic) sign.
For instance, in my own language NaN have no sign, but on the other hand I
use -Inf and +Inf :
That's completely fine.
It seems to me that using a sign bit on NaN is a design error.....
Possibly. But it's the more orthogonal choice with IEEE float (where
simply all specified values have a sign).
Ciao,
Michael.
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.
--
-- [email protected]
-- Développeur compulsif
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel