From 97a9dcf29e638ec9ec46b196a54c7f1113f0831e Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 27 Dec 2009 20:03:08 +0000 Subject: [PATCH] adding rounding mode and scale as per 1.2 JIRA: MATH-307 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@894107 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/math/util/BigReal.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/math/util/BigReal.java b/src/main/java/org/apache/commons/math/util/BigReal.java index 0b9b47514..b96990f38 100644 --- a/src/main/java/org/apache/commons/math/util/BigReal.java +++ b/src/main/java/org/apache/commons/math/util/BigReal.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; +import java.math.RoundingMode; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; @@ -43,11 +44,17 @@ public class BigReal implements FieldElement, Comparable, Seri public static final BigReal ONE = new BigReal(BigDecimal.ONE); /** Serializable version identifier. */ - private static final long serialVersionUID = 7887631840434052850L; + private static final long serialVersionUID = 4984534880991310382L; /** Underlying BigDecimal. */ private final BigDecimal d; + /** Rounding mode for divisions. **/ + private RoundingMode roundingMode = RoundingMode.HALF_UP; + + /*** BigDecimal scale ***/ + private int scale = 64; + /** Build an instance from a BigDecimal. * @param val value of the instance */ @@ -181,6 +188,40 @@ public class BigReal implements FieldElement, Comparable, Seri d = new BigDecimal(val, mc); } + /*** + * Gets the rounding mode for division operations + * The default is {@code RoundingMode.HALF_UP} + * @return the rounding mode. + */ + public RoundingMode getRoundingMode() { + return roundingMode; + } + + /*** + * Sets the rounding mode for decimal divisions. + * @param roundingMode rounding mode for decimal divisions + */ + public void setRoundingMode(RoundingMode roundingMode) { + this.roundingMode = roundingMode; + } + + /*** + * Sets the scale for division operations. + * The default is 64 + * @return the scale + */ + public int getScale() { + return scale; + } + + /*** + * Sets the scale for division operations. + * @param scale scale for division operations + */ + public void setScale(int scale) { + this.scale = scale; + } + /** {@inheritDoc} */ public BigReal add(BigReal a) { return new BigReal(d.add(a.d));