JDK-4920825 : Add divide methods taking RoundingMode objects
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2003-09-11
  • Updated: 2017-05-16
  • Resolved: 2003-09-26
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 :  
Description
Among the changes in jsr13 is the introduction of a RoundinMode enum class to replace uses of an integer enum pattern of rounding modes defined in BigDecimal.  The initial jsr13 proposal added a parallel method taking a RoundingMode object instead of an integer for one of the three uses of rounding mode integers as parameters.  The parallel method added was setScale; this bug is to add parallel methods for the other two uses; i.e. augment

   divide(BigDecimal divisor, int roundingMode)
   divide(BigDecimal divisor, int scale, int roundingMode) 

with

   divide(BigDecimal divisor, RoundingMode)
   divide(BigDecimal divisor, int scale, RoundingMode) 

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

SUGGESTED FIX src/share/classes/java/math>sccs sccsdiff -r1.46 -r1.47 BigDecimal.java ------- BigDecimal.java ------- 278c278 < * @throws NumberFormatException <tt>in</tt> is not a valid --- > * @throws NumberFormatException if <tt>in</tt> is not a valid 428c428 < * @throws NumberFormatException <tt>in</tt> is not a valid --- > * @throws NumberFormatException if <tt>in</tt> is not a valid 451c451 < * @throws NumberFormatException <tt>in</tt> is not a valid --- > * @throws NumberFormatException if <tt>in</tt> is not a valid 475c475 < * @throws NumberFormatException <tt>in</tt> is not a valid --- > * @throws NumberFormatException if <tt>in</tt> is not a valid 590,591c590,591 < @throws NumberFormatException <tt>val</tt> is not a valid < * representation of a <tt>BigDecimal</tt>. --- > * @throws NumberFormatException if <tt>val</tt> is not a valid > * representation of a <tt>BigDecimal</tt>. 607c607 < * @throws NumberFormatException <tt>val</tt> is not a valid --- > * @throws NumberFormatException if <tt>val</tt> is not a valid 902c902 < * @throws NumberFormatException <tt>val</tt> is infinite or NaN. --- > * @throws NumberFormatException if <tt>val</tt> is infinite or NaN. 1084c1084 < * <p>The new {@link #divide(BigDecimal, MathContext)} method --- > * <p>The new {@link #divide(BigDecimal, int, RoundingMode)} method 1091c1091 < * @throws ArithmeticException <tt>divisor</tt> is zero, --- > * @throws ArithmeticException if <tt>divisor</tt> is zero, 1095c1095 < * @throws IllegalArgumentException <tt>roundingMode</tt> does not --- > * @throws IllegalArgumentException if <tt>roundingMode</tt> does not 1165c1165,1185 < * val)</tt>, and whose scale is <tt>this.scale()</tt>. If --- > * divisor)</tt>, and whose scale is as specified. If rounding must > * be performed to generate a result with the specified scale, the > * specified rounding mode is applied. > * > * @param divisor value by which this <tt>BigDecimal</tt> is to be divided. > * @param scale scale of the <tt>BigDecimal</tt> quotient to be returned. > * @param roundingMode rounding mode to apply. > * @return <tt>this / divisor</tt> > * @throws ArithmeticException if <tt>divisor</tt> is zero, > * <tt>roundingMode==RoundingMode.UNNECESSARY</tt> and > * the specified scale is insufficient to represent the result > * of the division exactly. > * @since 1.5 > */ > public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode) { > return divide(divisor, scale, roundingMode.oldMode); > } > > /** > * Returns a <tt>BigDecimal</tt> whose value is <tt>(this / > * divisor)</tt>, and whose scale is <tt>this.scale()</tt>. If 1169c1189 < * <p>The new {@link #divide(BigDecimal, MathContext)} method --- > * <p>The new {@link #divide(BigDecimal, RoundingMode)} method 1175c1195 < * @throws ArithmeticException <tt>divisor==0</tt>, or --- > * @throws ArithmeticException if <tt>divisor==0</tt>, or 1179c1199 < * @throws IllegalArgumentException <tt>roundingMode</tt> does not --- > * @throws IllegalArgumentException if <tt>roundingMode</tt> does not 1193a1214,1230 > /** > * Returns a <tt>BigDecimal</tt> whose value is <tt>(this / > * divisor)</tt>, and whose scale is <tt>this.scale()</tt>. If > * rounding must be performed to generate a result with the given > * scale, the specified rounding mode is applied. > * > * @param divisor value by which this <tt>BigDecimal</tt> is to be divided. > * @param roundingMode rounding mode to apply. > * @return <tt>this / divisor</tt> > * @throws ArithmeticException if <tt>divisor==0</tt>, or > * <tt>roundingMode==RoundingMode.UNNECESSARY</tt> and > * <tt>this.scale()</tt> is insufficient to represent the result > * of the division exactly. > */ > public BigDecimal divide(BigDecimal divisor, RoundingMode roundingMode) { > return this.divide(divisor, scale, roundingMode.oldMode); > } 1204c1241 < * terminating decimal expansion --- > * terminating decimal expansion 1351c1388 < * @throws ArithmeticException <tt>divisor==0</tt> --- > * @throws ArithmeticException if <tt>divisor==0</tt> 1404c1441 < * @throws ArithmeticException <tt>divisor==0</tt> --- > * @throws ArithmeticException if <tt>divisor==0</tt> 1469c1506 < * @throws ArithmeticException <tt>divisor==0</tt> --- > * @throws ArithmeticException if <tt>divisor==0</tt> 1494,1495c1531 < * @throws ArithmeticException <tt>divisor==0</tt> < --- > * @throws ArithmeticException if <tt>divisor==0</tt> 1523c1559 < * @throws ArithmeticException <tt>divisor==0</tt> --- > * @throws ArithmeticException if <tt>divisor==0</tt> 1554c1590 < * @throws ArithmeticException <tt>divisor==0</tt> --- > * @throws ArithmeticException if <tt>divisor==0</tt> 1986c2022 < * @throws ArithmeticException <tt>roundingMode==ROUND_UNNECESSARY</tt> --- > * @throws ArithmeticException if <tt>roundingMode==ROUND_UNNECESSARY</tt> 1989c2025 < * @throws IllegalArgumentException <tt>roundingMode</tt> does not --- > * @throws IllegalArgumentException if <tt>roundingMode</tt> does not 2053c2089 < * @throws ArithmeticException the specified scaling operation would --- > * @throws ArithmeticException if the specified scaling operation would 2111,2112c2147,2148 < * @throws ArithmeticException If the scale would be < * outside the range of a 32-bit integer. --- > * @throws ArithmeticException if the scale would be > * outside the range of a 32-bit integer. ###@###.### 2003-09-15
15-09-2003

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