JDK-8253409 : Double-rounding possibility in float fma
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 11,15
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2020-09-21
  • Updated: 2021-03-22
  • Resolved: 2021-02-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 JDK 16 JDK 17
11.0.11Fixed 13.0.7Fixed 16.0.1Fixed 17 b11Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Ubuntu 18.04 on x86_64

$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
I found Math.fma(float, float, float) method returned different values with or without -XX:-UseFMA VM option for the same inputs.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Save the code as FMAExample.java
2. Run `javac FMAExample.java`
3. Run `java -XX:-UseFMA FMAExample`

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Step 3 prints out 0x1.000002p52
ACTUAL -
Step 3 printed out 0x1.000004p52

---------- BEGIN SOURCE ----------
public class FMAExample {
  public static void main(String[] args) {
    float a = 0x1.fffffep23f;
    float b = 0x1.000004p28f;
    float c = 0x1.fep5f;
    // The below line prints out different values for +/-UseFMA option.
    // -XX:+UseFMA: 0x1.000002p52
    // -XX:-UseFMA: 0x1.000004p52
    System.out.printf("%a\n", Math.fma(a, b, c));
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Do not specify `java -XX:-UseFMA FMAExample`


Comments
From the submitter: I have verified the bug was fixed with the JDK 17.
22-03-2021

Fix request (13u) Requesting backport to 13u for parity with 11u. The patch applies cleanly. Tested with tier1; new test fails without the patch, passes with it.
19-03-2021

Requested the submitter to verify the fix with the latest version of JDK at https://jdk.java.net/17/
10-03-2021

Fix Request (11u) Same as above. Should get fixed for parity with 11.0.11-oracle. Applies cleanly, too.
05-03-2021

Fix Request Address correctness issue for non-intrinsified float fma results. Change software implementation to straightforward float-specific code to avoid double-rounding by using the double version. Patch expected to apply cleanly.
23-02-2021

Changeset: e5304b3a Author: Joe Darcy <darcy@openjdk.org> Date: 2021-02-23 19:42:05 +0000 URL: https://git.openjdk.java.net/jdk/commit/e5304b3a
23-02-2021

The observations on Windows 10: JDK 11: Failed because Math.fma(float, float, float) returned different values with -XX:-UseFMA VM option JDK 15: Failed
21-09-2020