Details

Bug

Resolution: Fixed

P3

11, 14

b32

generic

generic

Verified
Backports
Issue  Fix Version  Assignee  Priority  Status  Resolution  Resolved In Build 

JDK8237292  15  Joe Darcy  P3  Resolved  Fixed  b07 
JDK8237700  14.0.2  Joe Darcy  P3  Resolved  Fixed  master 
JDK8238126  14.0.1  Unassigned  P3  Resolved  Fixed  b02 
JDK8256759  13.0.6  Yuri Nesterenko  P3  Resolved  Fixed  b01 
JDK8244070  11.0.9oracle  Fisba Samreen  P3  Resolved  Fixed  b01 
JDK8246655  11.0.9  Joe Darcy  P3  Resolved  Fixed  b01 
Description
Also tested OpenJDK 11.0.2 with the same result.
A DESCRIPTION OF THE PROBLEM :
The method java.math.BigDecimal.sqrt(MathContext mc) does not respect the intention of RoundingMode.FLOOR.
Other RoundingMode values have not been tested, but may also return incorrectly rounded results.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the simple source code snippet in a main method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED 
1.99999999999
ACTUAL 
2.00000000000
 BEGIN SOURCE 
MathContext mc = new MathContext(12, RoundingMode.FLOOR);
System.out.println(new BigDecimal("3.999999999999999999999999999999").sqrt(mc));
 END SOURCE 
CUSTOMER SUBMITTED WORKAROUND :
Using the sqrt() method of the bigmath library from https://github.com/eobermuhlner/bigmath does deliver the correct result.
FREQUENCY : always
Attachments
Issue Links
 backported by

JDK8237292 java.math.BigDecimal.sqrt() with RoundingMode.FLOOR results in incorrect result
 Resolved

JDK8237700 java.math.BigDecimal.sqrt() with RoundingMode.FLOOR results in incorrect result
 Resolved

JDK8238126 java.math.BigDecimal.sqrt() with RoundingMode.FLOOR results in incorrect result
 Resolved

JDK8244070 java.math.BigDecimal.sqrt() with RoundingMode.FLOOR results in incorrect result
 Resolved

JDK8246655 java.math.BigDecimal.sqrt() with RoundingMode.FLOOR results in incorrect result
 Resolved

JDK8256759 java.math.BigDecimal.sqrt() with RoundingMode.FLOOR results in incorrect result
 Resolved
 relates to

JDK8237801 Refine Netwon iteration termination conditions for BigDecimal.sqrt
 Open

JDK4851777 Add BigDecimal sqrt method
 Closed