groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/2] groovy git commit: Make DIVISION_EXTRA_PRECISION and DIVISION_MIN_SCALE configurable
Date Tue, 03 Jul 2018 09:31:19 GMT
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/b7f609a9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b7f609a9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b7f609a9

Branch: refs/heads/master
Commit: b7f609a96f390ffd4b64c2008192ff057ba18253
Parents: 94c9646
Author: sunlan <sunlan@apache.org>
Authored: Tue Jul 3 17:30:48 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Jul 3 17:30:48 2018 +0800

----------------------------------------------------------------------
 .../java/org/apache/groovy/util/SystemUtil.java    | 17 +++++++++++++++++
 .../runtime/typehandling/BigDecimalMath.java       |  6 ++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b7f609a9/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/b7f609a9/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 6a7aaf5..b8e89f1 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,11 +32,11 @@ 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 = 32;
+    public static final int DIVISION_EXTRA_PRECISION = SystemUtil.getIntegerSafe("groovy.division.extra.precision",
32);
 
     //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 = 32;
+    public static final int DIVISION_MIN_SCALE = SystemUtil.getIntegerSafe("groovy.division.min.scale",
32);
 
     public static final BigDecimalMath INSTANCE = new BigDecimalMath();
 


Mime
View raw message