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

182
Visualizações
Differences in floating point between JDK 8 and JDK 13

It seems that JDK 8 and JDK 13 have different floating points.
I get on JDK 8, using Math:

cos(2.3) = -0.666276021279824

And on JDK 13:

cos(2.3) = -0.6662760212798241

How does this happen? Difference shows on 11th Gen Intel and on AMD Ryzen using Windows 10.

Edit 20.03.2022:
Using Long.toHexString(Double.doubleToRawLongBits()) I get different bit patterns:
I get on JDK 8:

cos(2.3) = 0xbfe5522217302fe0

And I get on JDK 13:

cos(2.3) = 0xbfe5522217302fe1
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This seems to be caused by a JVM intrinsic function for Math.cos, which is described in the related issue JDK-8242461. The behavior experienced there is not considered an issue:

The returned results reported in this bug are indeed adjacent floating-point values [this is the case here as well]

[...]

Therefore, while it is possible one or the other of the returned values is outside of the accuracy bounds, just have different return values for Math.cos is not in and of itself evidence of a problem.

For reproducible results, use the StrictMath.cos instead.

And indeed, disabling the intrinsics using -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_dcos (as proposed in the linked issue), causes Math.cos to have the same (expected) result as StrictMath.cos.

So it appears the behavior you are seeing here is most likely compliant with the Math documentation as well.

over 4 years ago · Santiago Trujillo 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