You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/07/03 09:50:20 UTC
groovy git commit: GROOVY-8679: BigDecimalMath.MAX_DIVISION_SCALE is
hard-coded
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_5_X c7272cfa2 -> d6b1dbc44
GROOVY-8679: BigDecimalMath.MAX_DIVISION_SCALE is hard-coded
Make DIVISION_EXTRA_PRECISION and DIVISION_MIN_SCALE configurable
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d6b1dbc4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d6b1dbc4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d6b1dbc4
Branch: refs/heads/GROOVY_2_5_X
Commit: d6b1dbc44284f5051c125e409c0a7e40859fc98e
Parents: c7272cf
Author: sunlan <su...@apache.org>
Authored: Tue Jul 3 17:50:05 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Jul 3 17:50:05 2018 +0800
----------------------------------------------------------------------
.../java/org/apache/groovy/util/SystemUtil.java | 17 +++++++++++++++++
.../runtime/typehandling/BigDecimalMath.java | 9 +++++----
2 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b1dbc4/src/main/java/org/apache/groovy/util/SystemUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/groovy/util/SystemUtil.java b/src/main/java/org/apache/groovy/util/SystemUtil.java
index 2dfe692..66dc01e 100644
--- a/src/main/java/org/apache/groovy/util/SystemUtil.java
+++ b/src/main/java/org/apache/groovy/util/SystemUtil.java
@@ -119,4 +119,21 @@ public class SystemUtil {
}
return false;
}
+
+ /**
+ * Retrieves an Integer System property
+ *
+ * @param name the name of the system property.
+ * @param def the default value
+ * @return value of the Integer system property or false
+ */
+ public static Integer getIntegerSafe(String name, Integer def) {
+ try {
+ return Integer.getInteger(name, def);
+ } catch (SecurityException ignore) {
+ // suppress exception
+ }
+
+ return def;
+ }
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b1dbc4/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
index 96bf0f3..f362272 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
@@ -18,6 +18,8 @@
*/
package org.codehaus.groovy.runtime.typehandling;
+import org.apache.groovy.util.SystemUtil;
+
import java.math.BigDecimal;
import java.math.MathContext;
@@ -30,16 +32,15 @@ public final class BigDecimalMath extends NumberMath {
// This is an arbitrary value, picked as a reasonable choice for a precision
// for typical user math when a non-terminating result would otherwise occur.
- public static final int DIVISION_EXTRA_PRECISION = 10;
+ public static final int DIVISION_EXTRA_PRECISION = SystemUtil.getIntegerSafe("groovy.division.extra.precision", 10);
//This is an arbitrary value, picked as a reasonable choice for a rounding point
//for typical user math.
- public static final int DIVISION_MIN_SCALE = 10;
+ public static final int DIVISION_MIN_SCALE = SystemUtil.getIntegerSafe("groovy.division.min.scale", 10);
public static final BigDecimalMath INSTANCE = new BigDecimalMath();
- private BigDecimalMath() {
- }
+ private BigDecimalMath() {}
protected Number absImpl(Number number) {
return toBigDecimal(number).abs();