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:31:18 UTC
[1/2] groovy git commit: GROOVY-8679:
BigDecimalMath.MAX_DIVISION_SCALE is hard-coded
Repository: groovy
Updated Branches:
refs/heads/master 73b4a6f61 -> b7f609a96
GROOVY-8679: BigDecimalMath.MAX_DIVISION_SCALE is hard-coded
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/94c9646b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/94c9646b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/94c9646b
Branch: refs/heads/master
Commit: 94c9646b7010ab7244ddb5fa8d729eef901ec5b7
Parents: 73b4a6f
Author: Pierre Pinon <pi...@pinon1.fr>
Authored: Tue Jul 3 17:21:39 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Jul 3 17:21:39 2018 +0800
----------------------------------------------------------------------
.../org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java | 4 ++--
src/test/groovy/operator/BigDecimalOperatorsTest.groovy | 4 ++--
.../codehaus/groovy/runtime/typehandling/NumberMathTest.groovy | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/94c9646b/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..6a7aaf5 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
@@ -30,11 +30,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 = 10;
+ public static final int 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 = 10;
+ public static final int DIVISION_MIN_SCALE = 32;
public static final BigDecimalMath INSTANCE = new BigDecimalMath();
http://git-wip-us.apache.org/repos/asf/groovy/blob/94c9646b/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/operator/BigDecimalOperatorsTest.groovy b/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
index ace3194..10be290 100644
--- a/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
+++ b/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
@@ -90,10 +90,10 @@ class BigDecimalOperatorsTest extends GroovyTestCase {
assert y == 10 , "y = " + y
y = 34 / 3.000
- assert y == 11.3333333333 , "y = " + y
+ assert y == 11.33333333333333333333333333333333 , "y = " + y
y = 34.00000000000 / 3
- assert y == 11.33333333333 , "y = " + y
+ assert y == 11.33333333333333333333333333333333 , "y = " + y
}
BigDecimal echoX ( BigDecimal x, BigDecimal y) {x}
http://git-wip-us.apache.org/repos/asf/groovy/blob/94c9646b/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy b/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
index eff11ce..5a92005 100644
--- a/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
@@ -132,10 +132,10 @@ class NumberMathTest extends GroovyTestCase {
assert BI1.intdiv(BI2) == 0
assert I1 / I3 instanceof BigDecimal
- assert I1 / I3 == new BigDecimal("0.3333333333")
+ assert I1 / I3 == new BigDecimal("0.33333333333333333333333333333333")
assert I2 / I3 instanceof BigDecimal
- assert I2 / I3 == new BigDecimal("0.6666666667")
+ assert I2 / I3 == new BigDecimal("0.66666666666666666666666666666667")
assert I1 / BD2 instanceof BigDecimal
[2/2] groovy git commit: Make DIVISION_EXTRA_PRECISION and
DIVISION_MIN_SCALE configurable
Posted by su...@apache.org.
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 <su...@apache.org>
Authored: Tue Jul 3 17:30:48 2018 +0800
Committer: sunlan <su...@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();
Re: [1/2] groovy git commit: GROOVY-8679:
BigDecimalMath.MAX_DIVISION_SCALE is hard-coded
Posted by "Daniel.Sun" <su...@apache.org>.
Hi Paul,
I've reverted the commit this morning:
https://github.com/apache/groovy/commit/92222324030473ca64a2ab6b174d2fa865c29682
Cheers,
Daniel.Sun
-----
Daniel Sun
Apache Groovy committer
Blog: http://blog.sunlan.me
Twitter: @daniel_sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: [1/2] groovy git commit: GROOVY-8679: BigDecimalMath.MAX_DIVISION_SCALE
is hard-coded
Posted by Paul King <pa...@asert.com.au>.
Hi Daniel,
I think it is fine to make this configurable but I wouldn't change the
default.
That kind of breaking change is going to break lots of folk's builds.
Cheers, Paul.
On Tue, Jul 3, 2018 at 7:31 PM <su...@apache.org> wrote:
> Repository: groovy
> Updated Branches:
> refs/heads/master 73b4a6f61 -> b7f609a96
>
>
> GROOVY-8679: BigDecimalMath.MAX_DIVISION_SCALE is hard-coded
>
>
> Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
> Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/94c9646b
> Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/94c9646b
> Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/94c9646b
>
> Branch: refs/heads/master
> Commit: 94c9646b7010ab7244ddb5fa8d729eef901ec5b7
> Parents: 73b4a6f
> Author: Pierre Pinon <pi...@pinon1.fr>
> Authored: Tue Jul 3 17:21:39 2018 +0800
> Committer: sunlan <su...@apache.org>
> Committed: Tue Jul 3 17:21:39 2018 +0800
>
> ----------------------------------------------------------------------
> .../org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java | 4 ++--
> src/test/groovy/operator/BigDecimalOperatorsTest.groovy | 4 ++--
> .../codehaus/groovy/runtime/typehandling/NumberMathTest.groovy | 4 ++--
> 3 files changed, 6 insertions(+), 6 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/groovy/blob/94c9646b/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..6a7aaf5 100644
> ---
> a/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
> +++
> b/src/main/java/org/codehaus/groovy/runtime/typehandling/BigDecimalMath.java
> @@ -30,11 +30,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 = 10;
> + public static final int 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 = 10;
> + public static final int DIVISION_MIN_SCALE = 32;
>
> public static final BigDecimalMath INSTANCE = new BigDecimalMath();
>
>
>
> http://git-wip-us.apache.org/repos/asf/groovy/blob/94c9646b/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
> ----------------------------------------------------------------------
> diff --git a/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
> b/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
> index ace3194..10be290 100644
> --- a/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
> +++ b/src/test/groovy/operator/BigDecimalOperatorsTest.groovy
> @@ -90,10 +90,10 @@ class BigDecimalOperatorsTest extends GroovyTestCase {
> assert y == 10 , "y = " + y
>
> y = 34 / 3.000
> - assert y == 11.3333333333 , "y = " + y
> + assert y == 11.33333333333333333333333333333333 , "y = " + y
>
> y = 34.00000000000 / 3
> - assert y == 11.33333333333 , "y = " + y
> + assert y == 11.33333333333333333333333333333333 , "y = " + y
> }
>
> BigDecimal echoX ( BigDecimal x, BigDecimal y) {x}
>
>
> http://git-wip-us.apache.org/repos/asf/groovy/blob/94c9646b/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
> ----------------------------------------------------------------------
> diff --git
> a/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
> b/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
> index eff11ce..5a92005 100644
> ---
> a/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
> +++
> b/src/test/org/codehaus/groovy/runtime/typehandling/NumberMathTest.groovy
> @@ -132,10 +132,10 @@ class NumberMathTest extends GroovyTestCase {
> assert BI1.intdiv(BI2) == 0
>
> assert I1 / I3 instanceof BigDecimal
> - assert I1 / I3 == new BigDecimal("0.3333333333")
> + assert I1 / I3 == new
> BigDecimal("0.33333333333333333333333333333333")
>
> assert I2 / I3 instanceof BigDecimal
> - assert I2 / I3 == new BigDecimal("0.6666666667")
> + assert I2 / I3 == new
> BigDecimal("0.66666666666666666666666666666667")
>
> assert I1 / BD2 instanceof BigDecimal
>
>
>