Subject: Re: floating point negative zero
To: None <tech-userlevel@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: tech-userlevel
Date: 08/25/2007 08:53:37
On Fri, 24 Aug 2007, Terry Moore wrote:
> According to ISO C-1999 page 275, section 7.19.6.1, note 233:
>
> "The results of all floating conversions of a negative zero, and of 
> negative values that round to zero, include a minus sign".

Thank you; I missed that part of the printf spec.  (It's note 236 in the
N1124 draft that I have.)

> I suspect that this is also true of awk based on 'transitive closure of the 
> specs', since usually awk manuals define %g, %f, etc., in terms of C printf 
> -- but I haven't checked.

Probably.  OK, it seems that application code that does't ever want to
print a negative zero should use something like

	if (val == 0) { val = 0 }

to convert it to a positive zero before printing.

--apb (Alan Barrett)