JDK-4904082 : Semantics of divideInteger and remainder methods should be updated and clarified
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2003-08-11
  • Updated: 2021-03-17
  • Resolved: 2003-08-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
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
In the draft of jsr13 described in 4851776, the divideInteger and remainder methods are underspecified.  The 4851776-era implementation of divideInteger also returns a result with zero scale; in other words, all trailing zeros of the integer results are explicitly stored.

This has a number of problems:

1. This result can different from the result of an exact divide even if the exact quotient is an integer.  For example, by the exact divide scale rules

1200e2 / 100 = 12e2

while (abusing notation)

1200e2 divideInteger 100 = 1200

2. The rules can create unnecessary large representations; e.g.

by the exact divide rules

1e100 / 1 = 1e100

while divideInteger would return

10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

These problems can be solved by redefining a divideInteger method to use the same preferred scale as the exact divide.

As for remainder, the 4851776 remainder(BigDecimal, MathContext) JavaDoc does not clearly state that the MathContext's rounding effects apply to the implicit divide which determines the remainder and not to the remainder result itself.  The remainder computation should be described in terms of the results of the divideInteger method; e.g.

a.remainder(b) ==

a - (a.divideInteger(b)*b)

This also implicitly defines the preferred scale of the remainder.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b18
14-06-2004

EVALUATION A fine idea. ###@###.### 2003-08-10
10-08-2003