RFR: 8253409: Double-rounding possibility in float fma

Joe Darcy darcy at openjdk.java.net
Tue Feb 23 04:04:53 UTC 2021


In floating-point, usually doing an operation to double precision and then rounding to float gives the right result in float precision. One exception to this is fused multiply add (fma) where "a * b + c" is computed with a single rounding. This requires the equivalent of extra intermediate precision inside the operation. If a float fma is implemented using a double fma rounded to float, for some well-chosen arguments where the final result is near a half-way result in *float*, an incorrect answer will be computed due to double rounding. In more detail, the double result will round up and then the cast to float will round up again whereas a single rounding of the exact answer to float would only round-up once.

The new float fma implementation does the exact arithmetic using BigDecimal where possible, with guard to handle the non-finite and signed zero IEEE 754 details.

-------------

Commit messages:
 - 8253409: Double-rounding possibility in float fma

Changes: https://git.openjdk.java.net/jdk/pull/2684/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2684&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8253409
  Stats: 31 lines in 2 files changed: 3 ins; 11 del; 17 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2684.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2684/head:pull/2684

PR: https://git.openjdk.java.net/jdk/pull/2684


More information about the core-libs-dev mailing list