Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript returns -0 [duplicate]

Tags:

javascript

I was trying out a simple arithmetic on console where I tried to multiply 0 with -1. Interestingly, I got a -0 as answer, instead of 0.

Screenshot:

enter image description here

Can anyone explain these results?

like image 976
data_set Avatar asked Feb 15 '16 07:02

data_set


Video Answer


1 Answers

Under the IEEE standard.

Signed zero is zero with an associated sign. In ordinary arithmetic, −0 = +0 = 0. However, in computing, some number representations allow for the existence of two zeros, often denoted by −0 (negative zero) and +0 (positive zero). This occurs in some signed number representations for integers, and in most floating point number representations. The number 0 is usually encoded as +0, but can be represented by either +0 or −0.

like image 170
Fergus Avatar answered Sep 25 '22 09:09

Fergus