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 2021/09/19 10:18:54 UTC

[groovy] branch danielsun/tweak-compare-bigdecimal updated: Trivial tweak for comparing `BigInteger` instances

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-compare-bigdecimal
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/danielsun/tweak-compare-bigdecimal by this push:
     new 7c2a223  Trivial tweak for comparing `BigInteger` instances
7c2a223 is described below

commit 7c2a22376559905e1b199ab15cfdb1069f55a4dc
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Sep 19 18:18:30 2021 +0800

    Trivial tweak for comparing `BigInteger` instances
---
 .../codehaus/groovy/runtime/ScriptBytecodeAdapter.java   | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
index 005af8b..02bfbf2 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
@@ -40,6 +40,7 @@ import org.codehaus.groovy.runtime.wrappers.PojoWrapper;
 import org.codehaus.groovy.runtime.wrappers.Wrapper;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -741,6 +742,9 @@ public class ScriptBytecodeAdapter {
         if (leftClass == BigDecimal.class && rightClass == BigDecimal.class) {
             return ((BigDecimal) left).compareTo((BigDecimal) right) == 0;
         }
+        if (leftClass == BigInteger.class && rightClass == BigInteger.class) {
+            return ((BigInteger) left).compareTo((BigInteger) right) == 0;
+        }
         return DefaultTypeTransformation.compareEqual(left, right);
     }
 
@@ -772,6 +776,9 @@ public class ScriptBytecodeAdapter {
         if (leftClass == BigDecimal.class && rightClass == BigDecimal.class) {
             return ((BigDecimal) left).compareTo((BigDecimal) right) < 0;
         }
+        if (leftClass == BigInteger.class && rightClass == BigInteger.class) {
+            return ((BigInteger) left).compareTo((BigInteger) right) < 0;
+        }
         return compareTo(left, right) < 0;
     }
 
@@ -790,6 +797,9 @@ public class ScriptBytecodeAdapter {
         if (leftClass == BigDecimal.class && rightClass == BigDecimal.class) {
             return ((BigDecimal) left).compareTo((BigDecimal) right) <= 0;
         }
+        if (leftClass == BigInteger.class && rightClass == BigInteger.class) {
+            return ((BigInteger) left).compareTo((BigInteger) right) <= 0;
+        }
         return compareTo(left, right) <= 0;
     }
 
@@ -808,6 +818,9 @@ public class ScriptBytecodeAdapter {
         if (leftClass == BigDecimal.class && rightClass == BigDecimal.class) {
             return ((BigDecimal) left).compareTo((BigDecimal) right) > 0;
         }
+        if (leftClass == BigInteger.class && rightClass == BigInteger.class) {
+            return ((BigInteger) left).compareTo((BigInteger) right) > 0;
+        }
         return compareTo(left, right) > 0;
     }
 
@@ -826,6 +839,9 @@ public class ScriptBytecodeAdapter {
         if (leftClass == BigDecimal.class && rightClass == BigDecimal.class) {
             return ((BigDecimal) left).compareTo((BigDecimal) right) >= 0;
         }
+        if (leftClass == BigInteger.class && rightClass == BigInteger.class) {
+            return ((BigInteger) left).compareTo((BigInteger) right) >= 0;
+        }
         return compareTo(left, right) >= 0;
     }