This is a mirror of official site: http://jasper-net.blogspot.com/

Why computers have two zeros: +0 and -0

| Sunday, June 20, 2010
Here’s a strange detail of floating point arithmetic: computers have two versions of 0: positive zero and negative zero. Most of the time the distinction between +0 and -0 doesn’t matter, once in a while signed versions of zero come in handy.

If a positive quantity underflows to zero, it becomes +0. And if a negative quantity underflows to zero, it becomes -0. You could think of +0 (respectively, -0) as the bit pattern for a positive (negative) number too small to represent.

The IEEE floating point standard says 1/+0 should be +infinity and 1/-0 should be -infinity. This makes sense if you interpret +/- 0 as the ghost of a number that underflowed leaving behind only its sign. The reciprocal of a positive (negative) number too small to represent is a positive (negative) number too large to represent.

To demonstrate this, run the following C code.

int main()
{
   double x = 1e-200;
   double y = 1e-200 * x;
   printf("Reciprocal of +0: %g\n", 1/y);
   y = -1e-200*x;
   printf("Reciprocal of -0: %g\n", 1/y);
}

Read more: The Endeavour

Posted via email from .NET Info

1 comments:

Anonymous said...

top [url=http://www.c-online-casino.co.uk/]casino games[/url] check the latest [url=http://www.casinolasvegass.com/]online casino[/url] autonomous no consign reward at the leading [url=http://www.baywatchcasino.com/]casino
[/url].