x86_64 tcc doesn't set sign bit on NaNs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

x86_64 tcc doesn't set sign bit on NaNs

arnold
Hi.

I found this bug in current mob on the current gawk sources. Test case:

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

Can we get this fixed please?

Thanks!

Arnold

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Vincent Lefevre-10
On 2021-01-03 21:17:03 +0200, Arnold Robbins wrote:

> Hi.
>
> I found this bug in current mob on the current gawk sources. Test case:
>
> -----------------------------
> #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.

--
Vincent Lefèvre <[hidden email]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Michael Matz-4
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.

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.


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Christian Jullien-3
Hi Michael,
The fix does not make the test suite happy, at least, on Linux Aarch64 when clang is used (gcc and tcc are Ok):

./configure --strip-binaries --with-selinux --cc=clang --prefix=/home/jullien/tinycc/static
Binary directory    /home/jullien/tinycc/static/bin
TinyCC directory    /home/jullien/tinycc/static/lib/tcc
Library directory   /home/jullien/tinycc/static/lib
Include directory   /home/jullien/tinycc/static/include
Manual directory    /home/jullien/tinycc/static/share/man
Info directory      /home/jullien/tinycc/static/share/info
Doc directory       /home/jullien/tinycc/static/share/doc
Source path         /home/jullien/tinycc
C compiler          clang (11.0)
Target OS           Linux
CPU                 aarch64
Config              strip selinux
Creating config.mak and config.h

...

------------ test3 ------------
--- test.ref    2021-01-04 06:54:01.523848942 +0100
+++ test.out3   2021-01-04 06:54:03.523846911 +0100
@@ -653,7 +653,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan nan
+nantest: nan -nan
 1.200000 3.400000 -5.600000
 2.120000 0.500000 23000000000.000000
 da=123.000000
gmake[2]: *** [Makefile:128: test3] Error 1


-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Michael Matz
Sent: Monday, January 04, 2021 04:59
To: [hidden email]
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

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.

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.


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Christian Jullien-3
Also on OpenBSD x64 with clang 10

./configure --strip-binaries --with-selinux --cc=clang --prefix=/home/jullien/tinycc/static
Binary directory    /home/jullien/tinycc/static/bin
TinyCC directory    /home/jullien/tinycc/static/lib/tcc
Library directory   /home/jullien/tinycc/static/lib
Include directory   /home/jullien/tinycc/static/include
Manual directory    /home/jullien/tinycc/static/share/man
Info directory      /home/jullien/tinycc/static/share/info
Doc directory       /home/jullien/tinycc/static/share/doc
Source path         /home/jullien/tinycc
C compiler          clang (10.0)
Target OS           OpenBSD
CPU                 x86_64
Config              BSD ldl=no strip selinux
Creating config.mak and config.h
...
------------ test3 ------------
--- test.ref    Mon Jan  4 08:35:32 2021
+++ test.out3   Mon Jan  4 08:35:32 2021
@@ -573,7 +573,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan -nan
+nantest: -nan nan
 testing 'double'
 0 1 1 0 0 1
 1.000000 2.500000 3.500000 -1.500000 2.500000 0.400000 -1.000000
@@ -613,7 +613,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan -nan
+nantest: -nan nan
 testing 'long double'
 0 1 1 0 0 1
 1.000000 2.500000 3.500000 -1.500000 2.500000 0.400000 -1.000000
@@ -653,7 +653,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan -nan
+nantest: -nan nan
 1.200000 3.400000 -5.600000
 2.120000 0.500000 23000000000.000000
 da=123.000000
gmake[2]: *** [Makefile:128: test3] Error 1
------------ memtest ------------

-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Christian Jullien
Sent: Monday, January 04, 2021 07:18
To: [hidden email]
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

Hi Michael,
The fix does not make the test suite happy, at least, on Linux Aarch64 when clang is used (gcc and tcc are Ok):

./configure --strip-binaries --with-selinux --cc=clang --prefix=/home/jullien/tinycc/static
Binary directory    /home/jullien/tinycc/static/bin
TinyCC directory    /home/jullien/tinycc/static/lib/tcc
Library directory   /home/jullien/tinycc/static/lib
Include directory   /home/jullien/tinycc/static/include
Manual directory    /home/jullien/tinycc/static/share/man
Info directory      /home/jullien/tinycc/static/share/info
Doc directory       /home/jullien/tinycc/static/share/doc
Source path         /home/jullien/tinycc
C compiler          clang (11.0)
Target OS           Linux
CPU                 aarch64
Config              strip selinux
Creating config.mak and config.h

...

------------ test3 ------------
--- test.ref    2021-01-04 06:54:01.523848942 +0100
+++ test.out3   2021-01-04 06:54:03.523846911 +0100
@@ -653,7 +653,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan nan
+nantest: nan -nan
 1.200000 3.400000 -5.600000
 2.120000 0.500000 23000000000.000000
 da=123.000000
gmake[2]: *** [Makefile:128: test3] Error 1


-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Michael Matz
Sent: Monday, January 04, 2021 04:59
To: [hidden email]
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

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.

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.


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

arnold
In reply to this post by Michael Matz-4
Michael Matz <[hidden email]> wrote:

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

Yep, that was the issue. Sorry I wasn't clear.

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

It now works for me. Thanks for the fix!

> Thanks for the report, Arnold.

You're welcome.

Take it easy,

Arnold

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Michael Matz-4
In reply to this post by Christian Jullien-3
Hello,

On Mon, 4 Jan 2021, Christian Jullien wrote:

> Also on OpenBSD x64 with clang 10

Bah.  I could fix this generically with using signbit(3) to check
for the required sign flip, but I'm not sure how widespread it's
availability or correctnes is on other platforms.  So Hermans disabling
for clang works for me as well.


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Christian Jullien-3
As long as my script that tests many build tcc configurations is happy, I'm happy too :o)

-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Michael Matz
Sent: Monday, January 04, 2021 23:42
To: [hidden email]; [hidden email]
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

Hello,

On Mon, 4 Jan 2021, Christian Jullien wrote:

> Also on OpenBSD x64 with clang 10

Bah.  I could fix this generically with using signbit(3) to check
for the required sign flip, but I'm not sure how widespread it's
availability or correctnes is on other platforms.  So Hermans disabling
for clang works for me as well.


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Vincent Lefevre-10
In reply to this post by Michael Matz-4
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.

--
Vincent Lefèvre <[hidden email]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

arnold
Vincent Lefevre <[hidden email]> wrote:

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

It was definitely the "d = -d".  Sorry I wasn't more clear.

Arnold

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

grischka
In reply to this post by Michael Matz-4
Michael Matz wrote:
>
> So the current "-0.0-x" expansion of unary '-' needs a change.  It
> turned out to be a bit uglier than I wished for, ...

Hm, yes, the more as on x87 using just 'fchs' could be so easy.
Anyway, I tried to make it look a bit less ugly:

https://repo.or.cz/tinycc.git/commitdiff/aeb8f427e2be133d6a0a67b695eb9579f5fa4232

-- grischka

> ... but alas, fixed in mob.
>
> Thanks for the report, Arnold.


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
ian
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

ian
In reply to this post by Vincent Lefevre-10

Hi to all, and happy new year.

AFAIK neither -NaN nor +NaN have sense (how to put a sign at a 'not a number' ????).

So, d=-d is a non-sense too.

For instance, in my own language NaN have no sign, but on the other hand I use -Inf and +Inf :

? (/ -1 0)
-Inf.
? (/ 1 0)
+Inf.
? (* 0 (/ -1 0))
NaN


It seems to me that using a sign bit on NaN is a design error.....

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.

--
-- [hidden email]
-- Développeur compulsif

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: x86_64 tcc doesn't set sign bit on NaNs

Michael Matz-4
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.
>
> --
> -- [hidden email]
> -- Développeur compulsif
>
>
_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel