javascript maximum value
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-12 09:26:50
0
4
941

In js, Number.MAX_VALUE represents the maximum value that can be represented. If this value is exceeded, Infinity will appear, but my calculation below is difficult to understand

(Number.MAX_VALUE+123)==Number.MAX_VALUE   //true  why?
(Number.MAX_VALUE+Number.MAX_VALUE)==Number.MAX_VALUE  //false why?
console.log(5.3e-324)  //5e-324 why?

Who understands why this is? Can you explain it?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(4)
黄舟
  1. Because 123 is too small to change the high-digit expression

  2. Because Number.MAX_VALUE is large enough to change the expression of high digits

  3. 5.3e-324 of .3 is too small

Summary: In many cases, js will have difficulty ensuring the accuracy of floating point number calculations, such as 0.1 + 0.2 != 0.3 // true

曾经蜡笔没有小新

One hundred million plus one, after rounding, it is still one hundred million, which is almost the same truth. It’s not that precise

世界只因有你


It should just represent a numerical value. If the minus sign is separated from the number, it cannot be calculated

我想大声告诉你

In the first example, you just increase your number by a really tiny number: 123 according to 1.79^308 is nothing. So you "lost" some precision: it does not change the number.

In the second one, you exceed the max value, so your number is not a number anymore, it is Infinity.

by Mistalis from stackoverflow
something about Number.MAX_VALUE

说白了就是浮点数精度问题!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template