Subject: floating point negative zero
To: None <tech-userlevel@netbsd.org>
From: Alan Barrett <apb@cequrux.com>
List: tech-userlevel
Date: 08/24/2007 19:55:23
On at least the i386, the following C code prints "-0":

	double i = -1.0;
	i *= 0.0;
	print("%g\n", i);

So does the analogous awk code, as I discovered from PR 36831.

I understand that the underlying hardware floating point format
distinguishes between positive and negative zero, but I am not sure
that users want to see this distinction in the results from ordinary
calculations.

So:

a. What's the recommended way to normalise a floating point number,
   converting from negative zero to ordinary zero, and from assorted other
   non-normalised forms to their normalised counterparts?

b. Does it make sense for printf to expose the difference between
   -0 and 0?

c. Does it make sense for awk's print operator to expose the
   difference ebwteen -0 and 0?

--apb (Alan Barrett)