JDK-6325535 : BigDecimal.negate(MathContext) method rounds improperly in some cases
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-09-18
  • Updated: 2010-04-02
  • Resolved: 2005-09-30
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.
Other JDK 6
5.0u8Fixed 6 b55Fixed
Description
The BigDecimal.negate(MathContext) method rounds improperly in some cases.  It is implemented as 

plus(mc).negate()

i.e. to rounds before negating.  This gives the improper result if the rounding mode is asymetric with respect to sign, as round to +infinity and round to -infinity are.

Comments
SUGGESTED FIX src/share/classes/java/math>sccs sccsdiff -r1.57 -r1.58 BigDecimal.java ------- BigDecimal.java ------- 1963c1963 < * @throws ArithmeticException if or the result is inexact but the --- > * @throws ArithmeticException if the result is inexact but the 1968c1968 < return plus(mc).negate(); --- > return negate().plus(mc);
23-09-2005

EVALUATION Should be fixed.
18-09-2005