How ~ (tilde) Infinity becomes -1

~ Infinity my question is how does it evaluate -1.

~ Infinity = -1

console.log(~Infinity);
Run codeHide result

because

infinity + infinity = infinity

console.log(Infinity+Infinity)
Run codeHide result

or

Infinity-Infinity = NaN

console.log(Infinity-Infinity)
Run codeHide result

As the conclusion ~Infinitygoes to -1;

0
source share
1 answer

In the IEEE 754 floating point, a constant Infinityis represented by a value with all the bits of the fraction set to 0. When it was called by a 32-bit integer value when calculating the bitwise complement (unary operator ~), you get only zero, so the complement is all 1 bit or -1.

Positive Infinity:

01111111111100000000000000000000000000000000000000000000000000000

( ). 0, - 1 , - .

+3

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


All Articles