summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Balkissoon <abalkiss@redhat.com>2006-02-28 20:31:01 +0000
committerAnthony Balkissoon <abalkiss@redhat.com>2006-02-28 20:31:01 +0000
commit75cab7a09ca7f69edbcb47a31aceb7afd9f43fb3 (patch)
tree70bab9ac6c948d7beb3264b0f5b38538d7598007
parentc716f16c9ebf39b73dcf9b046a46a9e05b047eb5 (diff)
downloadclasspath-75cab7a09ca7f69edbcb47a31aceb7afd9f43fb3.tar.gz
2006-02-28 Anthony Balkissoon <abalkiss@redhat.com>
* java/math/BigDecimal.java: (divide(BigDecimal, int, RoundingMode)): New method. (divide(BigDecimal, RoundingMode)): Likewise. (divide(BigDecimal, int, int)): Removed incorrect throwing of exception when the new scale is < 0. (setScale(int, RoundingMode)): New method. (ulp): Likewise.
-rw-r--r--ChangeLog10
-rw-r--r--java/math/BigDecimal.java62
2 files changed, 69 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e42ba244e..4d07ae563 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-02-28 Anthony Balkissoon <abalkiss@redhat.com>
+
+ * java/math/BigDecimal.java:
+ (divide(BigDecimal, int, RoundingMode)): New method.
+ (divide(BigDecimal, RoundingMode)): Likewise.
+ (divide(BigDecimal, int, int)): Removed incorrect throwing of exception
+ when the new scale is < 0.
+ (setScale(int, RoundingMode)): New method.
+ (ulp): Likewise.
+
2006-02-27 Anthony Balkissoon <abalkiss@redhat.com>
* java/math/BigDecimal.java: Replaced occurences of BigInteger.valueOf
diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
index b1b76a32c..6d9724810 100644
--- a/java/math/BigDecimal.java
+++ b/java/math/BigDecimal.java
@@ -670,7 +670,38 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
{
return divide (val, scale, roundingMode);
}
+
+ /**
+ * Returns a BigDecimal whose value is (this / val), with the specified scale
+ * and rounding according to the RoundingMode
+ * @param val the divisor
+ * @param scale the scale of the BigDecimal returned
+ * @param roundingMode the rounding mode to use
+ * @return a BigDecimal whose value is approximately (this / val)
+ * @throws ArithmeticException if divisor is zero or the rounding mode is
+ * UNNECESSARY but the specified scale cannot represent the value exactly
+ * @since 1.5
+ */
+ public BigDecimal divide(BigDecimal val,
+ int scale, RoundingMode roundingMode)
+ {
+ return divide (val, scale, roundingMode.ordinal());
+ }
+ /**
+ * Returns a BigDecimal whose value is (this / val) rounded according to the
+ * RoundingMode
+ * @param val the divisor
+ * @param roundingMode the rounding mode to use
+ * @return a BigDecimal whose value is approximately (this / val)
+ * @throws ArithmeticException if divisor is zero or the rounding mode is
+ * UNNECESSARY but the specified scale cannot represent the value exactly
+ */
+ public BigDecimal divide (BigDecimal val, RoundingMode roundingMode)
+ {
+ return divide (val, scale, roundingMode.ordinal());
+ }
+
public BigDecimal divide(BigDecimal val, int newScale, int roundingMode)
throws ArithmeticException, IllegalArgumentException
{
@@ -678,9 +709,6 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
throw
new IllegalArgumentException("illegal rounding mode: " + roundingMode);
- if (newScale < 0)
- throw new ArithmeticException ("scale is negative: " + newScale);
-
if (intVal.signum () == 0) // handle special case of 0.0/0.0
return newScale == 0 ? ZERO : new BigDecimal (ZERO.intVal, newScale);
@@ -1346,6 +1374,23 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
}
/**
+ * Returns a BigDecimal whose value is the same as this BigDecimal but whose
+ * representation has a scale of <code>newScale</code>. If the scale is
+ * reduced then rounding may occur, according to the RoundingMode.
+ * @param newScale
+ * @param roundingMode
+ * @return a BigDecimal whose scale is as given, whose value is
+ * <code>this</code> with possible rounding
+ * @throws ArithmeticException if the rounding mode is UNNECESSARY but
+ * rounding is required
+ * @since 1.5
+ */
+ public BigDecimal setScale(int newScale, RoundingMode roundingMode)
+ {
+ return setScale(newScale, roundingMode.ordinal());
+ }
+
+ /**
* Returns a new BigDecimal constructed from the BigDecimal(String)
* constructor using the Double.toString(double) method to obtain
* the String.
@@ -1419,4 +1464,15 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
result = result.round(mc);
return result;
}
+
+ /**
+ * Returns the size of a unit in the last place of this BigDecimal. This
+ * returns a BigDecimal with [unscaledValue, scale] = [1, this.scale()].
+ * @return the size of a unit in the last place of <code>this</code>.
+ * @since 1.5
+ */
+ public BigDecimal ulp()
+ {
+ return new BigDecimal(BigInteger.ONE, scale);
+ }
}