search

Home  >  Q&A  >  body text

javascript maximum value

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?

曾经蜡笔没有小新曾经蜡笔没有小新2751 days ago976

reply all(4)I'll reply

  • 黄舟

    黄舟2017-06-12 09:28:50

    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

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-12 09:28:50

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

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-12 09:28:50


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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-12 09:28:50

    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

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

    reply
    0
  • Cancelreply