Subject: Re: floating point negative zero
To: Alan Barrett <apb@cequrux.com>
From: David Laight <david@l8s.co.uk>
List: tech-userlevel
Date: 08/24/2007 18:59:38
On Fri, Aug 24, 2007 at 07:55:23PM +0200, Alan Barrett wrote:
> 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)

I believe the current code is correct (but I can't remember why I think that!)
ie the difference between +0 and -0 should be visible to programs.
Possibly because someone who implemented a conformant FP package told me
that it was one place where the one I wrote was non-conformant.

OTOH I'm not sure about printf.

	David

-- 
David Laight: david@l8s.co.uk