Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda