123123 * 100×10<sup>1</sup>. In such cases, the new {@literal "1"} is
124124 * the leading digit position of the returned result.
125125 *
126+ * <p>For methods and constructors with a {@code MathContext}
127+ * parameter, if the result is inexact but the rounding mode is {@link
128+ * RoundingMode#UNNECESSARY UNNECESSARY}, an {@code
129+ * ArithmeticException} will be thrown.
130+ *
126131 * <p>Besides a logical exact result, each arithmetic operation has a
127132 * preferred scale for representing a result. The preferred
128133 * scale for each operation is listed in the table below.
@@ -478,8 +483,6 @@ public BigDecimal(char[] in, int offset, int len) {
478483 * @param offset first character in the array to inspect.
479484 * @param len number of characters to consider.
480485 * @param mc the context to use.
481- * @throws ArithmeticException if the result is inexact but the
482- * rounding mode is {@code UNNECESSARY}.
483486 * @throws NumberFormatException if {@code in} is not a valid
484487 * representation of a {@code BigDecimal} or the defined subarray
485488 * is not wholly within {@code in}.
@@ -780,8 +783,6 @@ public BigDecimal(char[] in) {
780783 *
781784 * @param in {@code char} array that is the source of characters.
782785 * @param mc the context to use.
783- * @throws ArithmeticException if the result is inexact but the
784- * rounding mode is {@code UNNECESSARY}.
785786 * @throws NumberFormatException if {@code in} is not a valid
786787 * representation of a {@code BigDecimal}.
787788 * @since 1.5
@@ -903,8 +904,6 @@ public BigDecimal(String val) {
903904 *
904905 * @param val string representation of a {@code BigDecimal}.
905906 * @param mc the context to use.
906- * @throws ArithmeticException if the result is inexact but the
907- * rounding mode is {@code UNNECESSARY}.
908907 * @throws NumberFormatException if {@code val} is not a valid
909908 * representation of a BigDecimal.
910909 * @since 1.5
@@ -974,8 +973,6 @@ public BigDecimal(double val) {
974973 * @param val {@code double} value to be converted to
975974 * {@code BigDecimal}.
976975 * @param mc the context to use.
977- * @throws ArithmeticException if the result is inexact but the
978- * RoundingMode is UNNECESSARY.
979976 * @throws NumberFormatException if {@code val} is infinite or NaN.
980977 * @since 1.5
981978 */
@@ -1082,8 +1079,6 @@ public BigDecimal(BigInteger val) {
10821079 * @param val {@code BigInteger} value to be converted to
10831080 * {@code BigDecimal}.
10841081 * @param mc the context to use.
1085- * @throws ArithmeticException if the result is inexact but the
1086- * rounding mode is {@code UNNECESSARY}.
10871082 * @since 1.5
10881083 */
10891084 public BigDecimal (BigInteger val , MathContext mc ) {
@@ -1117,8 +1112,6 @@ public BigDecimal(BigInteger unscaledVal, int scale) {
11171112 * @param unscaledVal unscaled value of the {@code BigDecimal}.
11181113 * @param scale scale of the {@code BigDecimal}.
11191114 * @param mc the context to use.
1120- * @throws ArithmeticException if the result is inexact but the
1121- * rounding mode is {@code UNNECESSARY}.
11221115 * @since 1.5
11231116 */
11241117 public BigDecimal (BigInteger unscaledVal , int scale , MathContext mc ) {
@@ -1180,8 +1173,6 @@ public BigDecimal(int val) {
11801173 *
11811174 * @param val {@code int} value to be converted to {@code BigDecimal}.
11821175 * @param mc the context to use.
1183- * @throws ArithmeticException if the result is inexact but the
1184- * rounding mode is {@code UNNECESSARY}.
11851176 * @since 1.5
11861177 */
11871178 public BigDecimal (int val , MathContext mc ) {
@@ -1225,8 +1216,6 @@ public BigDecimal(long val) {
12251216 *
12261217 * @param val {@code long} value to be converted to {@code BigDecimal}.
12271218 * @param mc the context to use.
1228- * @throws ArithmeticException if the result is inexact but the
1229- * rounding mode is {@code UNNECESSARY}.
12301219 * @since 1.5
12311220 */
12321221 public BigDecimal (long val , MathContext mc ) {
@@ -1400,8 +1389,6 @@ public BigDecimal add(BigDecimal augend) {
14001389 * @param augend value to be added to this {@code BigDecimal}.
14011390 * @param mc the context to use.
14021391 * @return {@code this + augend}, rounded as necessary.
1403- * @throws ArithmeticException if the result is inexact but the
1404- * rounding mode is {@code UNNECESSARY}.
14051392 * @since 1.5
14061393 */
14071394 public BigDecimal add (BigDecimal augend , MathContext mc ) {
@@ -1550,8 +1537,6 @@ public BigDecimal subtract(BigDecimal subtrahend) {
15501537 * @param subtrahend value to be subtracted from this {@code BigDecimal}.
15511538 * @param mc the context to use.
15521539 * @return {@code this - subtrahend}, rounded as necessary.
1553- * @throws ArithmeticException if the result is inexact but the
1554- * rounding mode is {@code UNNECESSARY}.
15551540 * @since 1.5
15561541 */
15571542 public BigDecimal subtract (BigDecimal subtrahend , MathContext mc ) {
@@ -1593,8 +1578,6 @@ public BigDecimal multiply(BigDecimal multiplicand) {
15931578 * @param multiplicand value to be multiplied by this {@code BigDecimal}.
15941579 * @param mc the context to use.
15951580 * @return {@code this * multiplicand}, rounded as necessary.
1596- * @throws ArithmeticException if the result is inexact but the
1597- * rounding mode is {@code UNNECESSARY}.
15981581 * @since 1.5
15991582 */
16001583 public BigDecimal multiply (BigDecimal multiplicand , MathContext mc ) {
@@ -2597,8 +2580,6 @@ public BigDecimal abs() {
25972580 *
25982581 * @param mc the context to use.
25992582 * @return {@code abs(this)}, rounded as necessary.
2600- * @throws ArithmeticException if the result is inexact but the
2601- * rounding mode is {@code UNNECESSARY}.
26022583 * @since 1.5
26032584 */
26042585 public BigDecimal abs (MathContext mc ) {
@@ -2625,8 +2606,6 @@ public BigDecimal negate() {
26252606 *
26262607 * @param mc the context to use.
26272608 * @return {@code -this}, rounded as necessary.
2628- * @throws ArithmeticException if the result is inexact but the
2629- * rounding mode is {@code UNNECESSARY}.
26302609 * @since 1.5
26312610 */
26322611 public BigDecimal negate (MathContext mc ) {
@@ -2659,8 +2638,6 @@ public BigDecimal plus() {
26592638 * @param mc the context to use.
26602639 * @return {@code this}, rounded as necessary. A zero result will
26612640 * have a scale of 0.
2662- * @throws ArithmeticException if the result is inexact but the
2663- * rounding mode is {@code UNNECESSARY}.
26642641 * @see #round(MathContext)
26652642 * @since 1.5
26662643 */
@@ -2842,9 +2819,6 @@ public BigInteger unscaledValue() {
28422819 * @param mc the context to use.
28432820 * @return a {@code BigDecimal} rounded according to the
28442821 * {@code MathContext} settings.
2845- * @throws ArithmeticException if the rounding mode is
2846- * {@code UNNECESSARY} and the
2847- * {@code BigDecimal} operation would require rounding.
28482822 * @see #plus(MathContext)
28492823 * @since 1.5
28502824 */
@@ -3093,6 +3067,7 @@ public BigDecimal scaleByPowerOfTen(int n) {
30933067 *
30943068 * @return a numerically equal {@code BigDecimal} with any
30953069 * trailing zeros removed.
3070+ * @throws ArithmeticException if scale overflows.
30963071 * @since 1.5
30973072 */
30983073 public BigDecimal stripTrailingZeros () {
@@ -4924,6 +4899,7 @@ private static boolean needIncrement(MutableBigInteger mdivisor, int roundingMod
49244899 *
49254900 * @return new {@code BigDecimal} with a scale possibly reduced
49264901 * to be closed to the preferred scale.
4902+ * @throws ArithmeticException if scale overflows.
49274903 */
49284904 private static BigDecimal createAndStripZerosToMatchScale (BigInteger intVal , int scale , long preferredScale ) {
49294905 BigInteger qr []; // quotient-remainder pair
@@ -4948,6 +4924,7 @@ private static BigDecimal createAndStripZerosToMatchScale(BigInteger intVal, int
49484924 *
49494925 * @return new {@code BigDecimal} with a scale possibly reduced
49504926 * to be closed to the preferred scale.
4927+ * @throws ArithmeticException if scale overflows.
49514928 */
49524929 private static BigDecimal createAndStripZerosToMatchScale (long compactVal , int scale , long preferredScale ) {
49534930 while (Math .abs (compactVal ) >= 10L && scale > preferredScale ) {
0 commit comments