Subject: Re: floating point negative zero
To: None <tech-userlevel@NetBSD.org>
From: Alan Barrett <firstname.lastname@example.org>
Date: 08/25/2007 11:41:23
On Sat, 25 Aug 2007, David Laight wrote:
> On Fri, Aug 24, 2007 at 05:19:50PM -0400, Terry Moore wrote:
> > According to ISO C-1999 page 275, section 220.127.116.11, note 233:
> > "The results of all floating conversions of a negative zero, and of
> > negative values that round to zero, include a minus sign".
> Maybe the word 'round' is intended to be significant ?
(Note that section 18.104.22.168 is talking specifically about printf
conversions, not about arithmetic with floats or doubles.)
> for (a = -1.0; a != 0.0; a /= 10.0);
> would give -0, but
> a = -1.0; a *= 0.0;
> would generate 0 because there is no rounding error.
I read it as meaning that printf("%.02f", -0.00001) should print "-0.00"
because the value to be printed rounds to negative zero under the %.02f
My current understanding of the printf("%f", -1.0 * 0.0) case is that
I couldn't find anywhere in the standard that specifies whether the
arithmetic results in a positive or negative zero; but if the arithmetic
does yield a negative zero then the printf is required to print "-0".
--apb (Alan Barrett)