This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 2251885 Minor tweak for `BigDecimal` and `BigInteger` further
2251885 is described below
commit 225188514f738cec9971a1ce24e63efc18791ad5
Author: Daniel Sun <[email protected]>
AuthorDate: Thu Dec 3 13:24:26 2020 +0800
Minor tweak for `BigDecimal` and `BigInteger` further
---
.../java/org/codehaus/groovy/runtime/typehandling/NumberMath.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
b/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
index 299c524..9ee014d 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
@@ -187,9 +187,15 @@ public abstract class NumberMath {
if (n instanceof Integer || n instanceof Long || n instanceof Byte ||
n instanceof Short) {
return BigInteger.valueOf(n.longValue());
}
+
+ if (n instanceof Float || n instanceof Double) {
+ BigDecimal bd = new BigDecimal(n.toString());
+ return bd.toBigInteger();
+ }
if (n instanceof BigDecimal) {
- return ((BigDecimal) n).toBigIntegerExact();
+ return ((BigDecimal) n).toBigInteger();
}
+
return new BigInteger(n.toString());
}