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

174
Views
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 answers
Answer question

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 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!