ygerzhedovich commented on code in PR #4422:
URL: https://github.com/apache/ignite-3/pull/4422#discussion_r1768406324


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/IgniteMath.java:
##########
@@ -88,6 +92,141 @@ public static byte addExact(byte x, byte y) {
         return (byte) r;
     }
 
+    /** Returns the sum of its arguments, extending result type for overflow 
avoidance. */
+    public static BigInteger add(long x, long y) {
+        return BigInteger.valueOf(x).add(BigInteger.valueOf(y));
+    }
+
+    /** Returns the sum of its arguments, extending result type for overflow 
avoidance. */
+    public static BigDecimal add(BigDecimal x, BigDecimal y) {
+        int maxPrecision = 
Commons.cluster().getTypeFactory().getTypeSystem().getMaxPrecision(SqlTypeName.DECIMAL);
+        return x.add(y, new MathContext(maxPrecision, UNNECESSARY));
+    }
+
+    /** Returns the sum of its arguments, extending result type for overflow 
avoidance. */
+    public static long add(int x, int y) {
+        return (long) x + y;
+    }
+
+    /** Returns the sum of its arguments, extending result type for overflow 
avoidance. */
+    public static int add(short x, short y) {
+        return x + y;
+    }
+
+    /** Returns the sum of its arguments, extending result type for overflow 
avoidance. */
+    public static short add(byte x, byte y) {
+        return (short) (x + y);
+    }
+
+    /** Returns the subtraction of its arguments, extending result type for 
overflow avoidance. */
+    public static BigInteger subtract(long x, long y) {
+        return BigInteger.valueOf(x).subtract(BigInteger.valueOf(y));
+    }
+
+    /** Returns the subtraction of its arguments, extending result type for 
overflow avoidance. */
+    public static BigDecimal subtract(BigDecimal x, BigDecimal y) {
+        int maxPrecision = 
Commons.cluster().getTypeFactory().getTypeSystem().getMaxPrecision(SqlTypeName.DECIMAL);
+        return x.subtract(y, new MathContext(maxPrecision, UNNECESSARY));
+    }
+
+    /** Returns the subtraction of its arguments, extending result type for 
overflow avoidance. */
+    public static long subtract(int x, int y) {
+        return (long) x - y;
+    }
+
+    /** Returns the subtraction of its arguments, extending result type for 
overflow avoidance. */
+    public static int subtract(short x, short y) {
+        return x - y;
+    }
+
+    /** Returns the subtraction of its arguments, extending result type for 
overflow avoidance. */
+    public static short subtract(byte x, byte y) {
+        return (short) (x - y);
+    }
+
+    /** Returns the multiply of its arguments, extending result type for 
overflow avoidance. */
+    public static BigInteger multiply(long x, long y) {
+        return BigInteger.valueOf(x).multiply(BigInteger.valueOf(y));
+    }
+
+    /** Returns the multiply of its arguments, extending result type for 
overflow avoidance. */
+    public static BigDecimal multiply(BigDecimal x, long y) {
+        int maxPrecision = 
Commons.cluster().getTypeFactory().getTypeSystem().getMaxPrecision(SqlTypeName.DECIMAL);
+        return x.multiply(BigDecimal.valueOf(y), new MathContext(maxPrecision, 
UNNECESSARY));
+    }
+
+    /** Returns the multiply of its arguments, extending result type for 
overflow avoidance. */
+    public static BigDecimal multiply(BigDecimal x, BigDecimal y) {
+        int maxPrecision = 
Commons.cluster().getTypeFactory().getTypeSystem().getMaxPrecision(SqlTypeName.DECIMAL);

Review Comment:
   Standard (see 6.29) says for the case the following:
   `The precision of the result of multiplication is implementation-defined, 
and the scale is S1 +
   S2.`



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to