**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 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 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".
>
> Maybe the word 'round' is intended to be significant ?
(Note that section 1.19.6.1 is talking specifically about printf
conversions, not about arithmetic with floats or doubles.)
> so
> 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
format.
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)