Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
javascript: Why is Number.MAX_SAFE_INTEGER + 2.000000000000001 different than Number.MAX_SAFE_INTEGER + 2.0000000000000001?

It is said on Wikipedia that the representable numbers between 2⁵³ ~ 2⁵⁴ are all even integers.

If we let N = Number.MAX_SAFE_INTEGER (which is 2⁵³ - 1 = 9007199254740991), and calculate the following numbers: N+2, N+2.0000000000000001, N+2.000000000000001, I would expect that they are all the same, but I was wrong:

N + 2                  === 9007199254740992
N + 2.0000000000000001 === 9007199254740992
N + 2.000000000000001  === 9007199254740994

Does anyone know why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The first number, has a sub-decimal point component requiring 2^-56 exponent :

<<< '2.0000000000000001' gawk -v PREC=2000000 -nMbe '{
   
    printf("\n\t0x%.16A\n\n",($0)%1) }'

    0x 7.34ACA5F6226F0ADAp-56

the final 1 at the tail will be lost even during parsing, which means you're only asking it to handle

     [ 4^3^3/2 - 1 ] (ps:: this is my favorite 
                            way to express 2^53-1)
               + 2

which I'm guessing double-precision floating point logic defaults to not rounding it up. But conversely, the 2nd example you've provided has a sub-decimal component that is

     0x 4.80EBE7B9D58566C8 p-52

     i.e.

     0.00000000000000 10000000000
     0.000000000000000 2220446049 (~2^-52)

Combining both, what the floating point system sees is

     0x 2.000000000000 0 p+0 <~~~ 1st one
     0x 2.000000000000 5 p+0 <~~~ 2nd one 
                      /
                This 5 made all the difference

now the mantissa has something to use to round things up.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!