Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In IEEE 754 and JavaScript, how is 0 and -0 represented differently?

I am curious as to, even 0 === -0, but 1/0 and 1/-0 give different results. So we can probably assume that 0 and -0 are represented differently in IEEE 754. How are they represented?

Update: so far, I can find some info on https://en.wikipedia.org/wiki/Signed_zero

and it seems that there are IEEE 754-1985 and IEEE 754-2008, and one form might be, in binary:

0 00000000 00000000000000000000000  as positive 0
1 00000000 00000000000000000000000  as negative 0

(the above is 32 bit, with the left most bit the sign bit, then to the right, 8 bit as exponent, and then 23 bit as the significand). But I can't find the different between the 1985 and 2008 version.

like image 246
nonopolarity Avatar asked Nov 11 '22 15:11

nonopolarity


1 Answers

See:

IEEE 754-1985 on Wikipedia

IEEE 754-2008 on Wikipedia

and for the changes see the "IEEE 754 revision" page on Wikipedia.

Both 1985 and 2008 versions are using signed zero. They are represented as:

sign = 0 for positive zero, 1 for negative zero.

biased exponent = 0.

fraction = 0.

(exactly as you wrote in your question)

Edit: in both 1985 and 2008 version, 1/0 = infinity while 1/-0 = negative infinity.

like image 177
Daew Avatar answered Nov 14 '22 21:11

Daew