🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Peter Miller Fri, 07 Aug 1992 19:51
IEEE zero problem
#310
Author: Peter Miller
Date: Fri, 07 Aug 1992 19:51
33 lines
1373 bytes
Dear Sir,

IEEE has two representations for zero: -0.0 and +0.0.

The optimizer appears to think that there is only one.

For example:
	if (x == 0. && x < 0.)
		x = 0.;
if a line of code I use to make sure that zeros are always printed as positive.
The optimizer thinks the test is always false, which is not the case.

Another thing I tried was
	if (x == 0.)
		x = 0.;
which the optimizer promptly removed.

This behaviour is not correct, becauses there are two values of x which
equal 0.0 in IEEE fp math, and the optimizer erroneously thinks there is
only one.  The IEEE defn also asserts that -0. < 0.  Sigh.

I am using gcc-2.2.2 configured as sparc-sun-sunos4.1.
Is there a patach available to fix this mis-optimization?

The work around I am using is
	#ifdef __GNUC__
	__volatile__
	#endif
	double	x;
which looks rather groteque but does what I want (defeats the optimization).

Regards
Peter Miller
Re: IEEE zero problem
#320
Author: Paul Eggert
Date: Sat, 08 Aug 1992 16:13
9 lines
994 bytes
   This behaviour is not correct, becauses there are two values of x which
   equal 0.0 in IEEE fp math, and the optimizer erroneously thinks there is
   only one.  The IEEE defn also asserts that -0. < 0.

No, the IEEE 754 standard says that -0.0 == 0.0, and that !(-0.0 < 0.0).
You cannot directly distinguish -0.0 from 0.0 with a standard comparison op;
you can distinguish them only by printing them out, or by performing some
other arithmetic operations on them (e.g. 1/x) and comparing the results.
So GCC is acting correctly in the cases that you cite.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads