[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: Mon, 4 Jan 2021 04:59:28 +0100 (CET)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)


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.

While the interpretation of sign bits in NaNs isn't specified in IEEE754/854/P754, its existence is a given (in particular it talks about "the sign of a NaN", in order to say that their interpretation isn't determined :) )

Further IEEE754 recommends implementations to provide a negate(x) operation that copies x with reversed sign, that is to work on NaNs (and due to copysign needs to have observable behaviour). C99 and up specify that the unary '-' operator maps to that operation.

So, I think it's pretty clear, that whatever the sign bit of NaNs is supposed to mean, it must be switchable by unary '-' when IEEE754 conformance is claimed. We currently don't claim so, but we aim for it if possible :)

So the current "-0.0-x" expansion of unary '-' needs a change. It turned out to be a bit uglier than I wished for, but alas, fixed in mob.

Thanks for the report, Arnold.


reply via email to

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