Why is Number.MAX_SAFE_INTEGER 9,007,199,254,740,991 and not 9,007,199,254,740,992?

前端 未结 2 855
我寻月下人不归
我寻月下人不归 2020-12-24 05:29

ECMAScript 6\'s Number.MAX_SAFE_INTEGER supposedly represents the maximum numerical value JavaScript can store before issues arise with floating point precision

相关标签:
2条回答
  • 2020-12-24 05:45

    the only number which is in close proximity of another when compared with its next number shows true

    9007199254740992 == 9007199254740993
    true
    9007199254740993 == 9007199254740994
    false
    9007199254740991 == 9007199254740992
    false
    9007199254740997 == 9007199254740998
    false
    
    0 讨论(0)
  • 2020-12-24 05:50

    I would say its because while Math.pow(2, 53) is the largest directly representable integer, its unsafe in that its also the first value who's representation is also an approximation of another value:

    9007199254740992 == 9007199254740993 // true

    In contrast to Math.pow(2, 53) - 1:

    9007199254740991 == 9007199254740993 // false

    0 讨论(0)
提交回复
热议问题