[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

From: Michael Matz
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs
Date: Wed, 6 Jan 2021 07:42:08 +0100 (CET)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)


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).


Regards to all, and best wishes.


Le 05/01/2021 à 10:27, Vincent Lefevre a écrit :

On 2021-01-04 04:59:28 +0100, Michael Matz wrote:


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;


        $ 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]