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

200
Visualizações
Math.sin() behaving strangely in javascript

For some reason when I input Math.PI and 3.14 I get completely different and even impossible results

Edit: Nevermind, I'm just dumb and didn't notice the e-16

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

0

It gives ~10^-16 something very close to zero you can

console.log(Math.sin(Math.PI).toFixed(2))

about 4 years ago · Juan Pablo Isaza Relatório

0

Here I have set up a test of your problem

console.log(Math.sin(3.14));
console.log(Math.sin(Math.PI));

When run, I get this result:

0.0015926529164868282
1.2246467991473532e-16

The 2nd number is a really really small positive number. It is essentially 0. The first number is slightly larger, but 3.14 is a rounded value of PI, and that's why you get the difference

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