Javascript returns -0

I tried simple arithmetic on the console, where I tried to multiply 0 by -1. Interestingly, I got -0 as the answer, not 0.

Screenshot:

enter image description here

Can anyone explain these results?

+5
source share
4 answers

Javascript uses IEEE 754 as mentioned above as well

The IEEE 754 standard for floating point arithmetic (most computers and programming languages ​​that support floating point numbers are currently used) requires both +0 and -0. Real arithmetic with signed zeros can be considered as a variant of the extended line of real numbers, so 1 / -0 = -∞ and 1 / + 0 = + ∞; division is only undefined for Β± 0 / Β± 0 and Β± ∞ / Β± ∞.

A negatively signed zero echoes the concept of mathematical analysis approaching 0 from the bottom as a one-way limit, which can be denoted by x β†’ 0-, x β†’ 0- or x β†’ ↑ 0. The notation β€œ-0” can be used informally to denote a small negative number, rounded to zero. The concept of negative zero also has some theoretical applications in statistical mechanics and other disciplines.

It is argued that the inclusion of signed zero in IEEE 754 makes it much easier to achieve numerical accuracy in some critical problems ( http://people.freebsd.org/~das/kahan86branch.pdf ), in particular when calculating with complex elementary functions.

http://www.johndcook.com/blog/2010/06/15/why-computers-have-signed-zero/

+1
source

In accordance with the IEEE standard .

The signed zero is zero with a sign. In ordinary arithmetic, -0 = +0 = 0. However, when calculating, some representations of numbers allow two zeros to exist, often denoted by -0 (negative zero) and +0 (positive zero). This happens in some signed representation number for integers, and in most floating point numbers, representations. The number 0 is usually encoded as +0, but can be represented by either +0 or -0.

+5
source

JavaScript uses IEEE-754, which has both positive and negative zeros.

+2
source

JavaScript uses the standard IEEE 754 floating point system. This system has positive and negative zeros , although they are equal in comparison. It also has positive and negative infinity and meanings of "not numbers."

0
source

Source: https://habr.com/ru/post/1243024/


All Articles