Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
Why is initial value of exponent -1128 in deconstructing number in a sign, an integer coefficient, and an exponent?

Background: I am reading "How Numbers Work" in the book How JavaScript Works by Douglas Crockford.

A number in JavaScript is represented as number = sign * coefficient * (2 ** exponent). I understand this but then there is a function deconstruct to represent an integer using the sign, coefficient, and exponent.

In order to find the exponent, the initial value is taken as -1128

which is the exponent of 'Number.MIN_VALUE' minus the number of bits in the significand minus the bonus bit.

function deconstruct(number) {
   // .....
   exponent = -1128;
   let reduction = coefficient;
   while (reduction !== 0) {
   // .....
}

Why is exponent = -1128? I did not get the reason for starting with this number, please help me in understanding this.

The complete deconstruct function as mentioned in the book.

A similar question is asked here but I did not understand the answer.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think Crockford chose this value so that the resulting coefficient is always a 53-bit integer.

The deconstruct function determines the exponent by repeatedly dividing by two, and counting how long it takes to reach 0. For the number 1, which has an exponent of 0 (for a coefficient of 1.0), it takes 1075 steps, so by starting at -1075 and counting up we'd arrive at the exponent of 0. However, to get the long coefficient, we want to arrive at an exponent of -53, so we have to start at -1128 already.

Another way to put it: Number.MIN_VALUE, which is 1 * 2**-1074, needs to be multiplied by 2 1074 times to arrive at 1, then some more times to get the long coefficient.

Notice there are multiple off-by-one mistakes to be made here:

  • to get the value 1 (a 1-bit integer) as a 53-bit integer, we need an exponent of -52 not -53
  • the loop to compute the exponent overshoots by 1 as it reaches 0
  • of the 53 significant bits, only 52 bits are stored in the significand, there's a hidden implicit 1 bit (for normal numbers)

And Crockford actually made one of them! If you check out the maths, 1074 (exponent of MIN_VALUE) + 52 (significand binary digits) + 1 ("bonus bit", whatever that refers to) amounts to 1127, not 1128. Calling the deconstruct function will return a .coefficient with 54 binary digits, which is one too many.

That said, I think even the goal is questionable. Having the coefficient, which is actually a fractional number starting with 1.…, represented as an integer may be excused as a teaching device for the book. But it doesn't make any sense to represent subnormal numbers (whose coefficients are fractional numbers 0.…) as numbers larger than 252, with barely any significant digits.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda