Cole-Greer commented on code in PR #3121:
URL: https://github.com/apache/tinkerpop/pull/3121#discussion_r2112331811


##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -104,6 +104,16 @@ convert all of them to floating point.
 BigDecimal and BigInteger may not be supported depending on the language and 
Storage, therefore the behavior of type
 casting for these two types can vary depending on a Graph provider.
 
+**Number Promotion on Mathematical Operations**
+
+On math operations (when used in steps such as sum/sack) the highest common 
number class between
+the two inputs us used. Any number being floating point forces a floating 
point result.

Review Comment:
   ```suggestion
   the two inputs is used. Any number being floating point forces a floating 
point result.
   ```



##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/NumberHelperTest.java:
##########
@@ -99,20 +114,38 @@ public class NumberHelperTest {
             );
 
     private final static List<Triplet<Number, Number, String>> OVERFLOW_CASES 
= Arrays.asList(
-            new Triplet<>(Integer.MAX_VALUE, 1, "add"),
-            new Triplet<>(Integer.MIN_VALUE, 1, "sub"),
-            new Triplet<>(Integer.MAX_VALUE, Integer.MAX_VALUE, "mul"),
             new Triplet<>(Long.MAX_VALUE, 1L, "add"),
             new Triplet<>(Long.MIN_VALUE, 1L, "sub"),
-            new Triplet<>(Long.MAX_VALUE,  Integer.MAX_VALUE, "mul"),
-            new Triplet<>(Byte.MAX_VALUE, (byte)100, "add"),
-            new Triplet<>(Byte.MIN_VALUE, (byte)100, "sub"),
-            new Triplet<>((byte)100, (byte)100, "mul"),
-            new Triplet<>(Short.MAX_VALUE, (short)100, "add"),
-            new Triplet<>(Short.MIN_VALUE, (short)100, "sub"),
-            new Triplet<>(Short.MAX_VALUE, (short)100, "mul")
+            new Triplet<>(Long.MIN_VALUE, -1L, "mul"),
+            new Triplet<>(Long.MIN_VALUE, -1L, "div"),
+            new Triplet<>(Long.MAX_VALUE,  Integer.MAX_VALUE, "mul")
+    );
+
+    private final static List<Quartet<Number, Number, String, String>> 
NO_OVERFLOW_CASES = Arrays.asList(
+            new Quartet<>(Byte.MAX_VALUE, (byte)100, "add", "s"),
+            new Quartet<>(Byte.MIN_VALUE, (byte)100, "sub", "s"),
+            new Quartet<>((byte)100, (byte)100, "mul", "s"),
+            new Quartet<>(Byte.MAX_VALUE, 0.5f, "div", "f"),
+            new Quartet<>(Short.MAX_VALUE, (short)100, "add", "i"),
+            new Quartet<>(Short.MIN_VALUE, (short)100, "sub", "i"),
+            new Quartet<>(Short.MAX_VALUE, (short)100, "mul", "i"),
+            new Quartet<>(Short.MAX_VALUE, 0.5f, "div", "f"),
+            new Quartet<>(Integer.MAX_VALUE, 1, "add", "l"),
+            new Quartet<>(Integer.MIN_VALUE, 1, "sub", "l"),
+            new Quartet<>(Integer.MAX_VALUE, Integer.MAX_VALUE, "mul", "l"),
+            new Quartet<>(Integer.MAX_VALUE, 0.5f, "div", "f"),
+            new Quartet<>(Long.MAX_VALUE, 0.5f, "div", "d")

Review Comment:
   Would be good to add cases for
   ```
   new Quartet<>(Byte.MIN_VALUE, (byte)-1, "div", "s"),
   new Quartet<>(Short.MIN_VALUE, (short)-1, "div", "i"),
   new Quartet<>(Integer.MIN_VALUE, -1, "div", "l"),
   ```



-- 
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: commits-unsubscr...@tinkerpop.apache.org

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

Reply via email to