-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
tiger
-
generic
-
generic
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.
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.
- relates to
-
JDK-4609098 Add Decimal Arithmetic Enhancements into J2SE (JSR-013)
-
- Closed
-
-
JDK-8263726 divideToIntegralValue typo on BigDecimal documentation
-
- Resolved
-
-
JDK-4917089 sqe-lib : prototype :Tiger java.math.BigDecimal divideToIntegralValue(divisor,m
-
- Closed
-
-
JDK-4851776 Allow control of precision and rounding of BigDecimal arithmetic operations
-
- Resolved
-