Technically, "safe" in this context means "can you store this number *and
all numbers below it* without loss of precision", and for every single one
of these numbers, you can still add one to them. When you get up to 2^53,
you can no longer add just 1 - you can only add 2 or more. This is based on
the number of significand bits - 2^53 - 1 has all lower 53 bits set and its
exponent set to 0 (ignoring bias). You can precisely store up to this
number without having to adjust the exponent, no more. This is what is
meant by "safe". (The terminology of "exactly representable" is a misnomer
- the highest integer you can theoretically represent without loss of
precision is `(2^53-1) * (2^971)`.)

This SO answer should help explain the situation better:
https://stackoverflow.com/a/1848762


-----

Isiah Meadows
m...@isiahmeadows.com
www.isiahmeadows.com

On Sun, May 6, 2018 at 11:58 AM, Anders Rundgren <
anders.rundgren....@gmail.com> wrote:

> If you write
> Number.MAX_SAFE_INTEGER
> into a browser console it will return
> 9007199254740991
>
> I believe this is wrong, 9007199254740992 the largest correct safe integer
> using IEEE-754 double precision.
>
> Using my own IEEE-754 debugger:
>
> Input floating point: 9007199254740991
> Hex value: 433fffffffffffff
> Binary value: 0 10000110011 111111111111111111111111111111
> 1111111111111111111111
>
> Input floating point: 9007199254740992
> Hex value: 4340000000000000
> Binary value: 0 10000110100 000000000000000000000000000000
> 0000000000000000000000
>
> Using an external IEEE-754 debugger:
> http://www.binaryconvert.com/result_double.html?decimal=0570
> 48048055049057057050053052055052048057057050
>
> Anders
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to