danielsun1106 commented on a change in pull request #1437:
URL: https://github.com/apache/groovy/pull/1437#discussion_r532598636



##########
File path: 
src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
##########
@@ -168,11 +168,26 @@ public static boolean isBigInteger(Number number) {
     }
 
     public static BigDecimal toBigDecimal(Number n) {
-        return (n instanceof BigDecimal ? (BigDecimal) n : new 
BigDecimal(n.toString()));
+        if (n instanceof BigDecimal) {
+            return (BigDecimal) n;
+        }
+        if (n instanceof BigInteger) {
+            return new BigDecimal((BigInteger) n);
+        }
+        if (n instanceof Byte || n instanceof Short || n instanceof Integer || 
n instanceof Long) {

Review comment:
       I suggest to put Integer and Long at the beginning to avoid checks as 
possible as we could, because we use Integer and Long more often in the life 😉

##########
File path: 
src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
##########
@@ -168,11 +168,26 @@ public static boolean isBigInteger(Number number) {
     }
 
     public static BigDecimal toBigDecimal(Number n) {
-        return (n instanceof BigDecimal ? (BigDecimal) n : new 
BigDecimal(n.toString()));
+        if (n instanceof BigDecimal) {
+            return (BigDecimal) n;
+        }
+        if (n instanceof BigInteger) {
+            return new BigDecimal((BigInteger) n);
+        }
+        if (n instanceof Byte || n instanceof Short || n instanceof Integer || 
n instanceof Long) {
+            return new BigDecimal(n.longValue());
+        }
+        return new BigDecimal(n.toString());
     }
 
     public static BigInteger toBigInteger(Number n) {
-        return (n instanceof BigInteger ? (BigInteger) n : new 
BigInteger(n.toString()));
+        if (n instanceof BigInteger) {
+            return (BigInteger) n;
+        }
+        if (n instanceof Byte || n instanceof Short || n instanceof Integer || 
n instanceof Long) {

Review comment:
       Ditto




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to