caicancai commented on code in PR #3689:
URL: https://github.com/apache/calcite/pull/3689#discussion_r1497566850


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -2788,6 +2788,18 @@ public static double log(BigDecimal d0, BigDecimal d1) {
     return Math.log(d0.doubleValue()) / Math.log(d1.doubleValue());
   }
 
+  /** SQL {@code LOG2(number)} function applied to double values. */
+  public static double log2(double d0) {
+    return (Double.isInfinite(log(d0, 2)) && d0 == 0.0) ? Double.NaN : log(d0, 
2);
+  }
+
+  /** SQL {@code LOG2(number)} function applied to
+   * BigDecimal and double values. */
+  public static double log2(BigDecimal d0) {
+    return (Double.isInfinite(log(d0, 2)) && d0.doubleValue() == 0.0) ? 
Double.NaN : log(d0, 2);

Review Comment:
   To a certain extent, I agree with your point of view, but if it is just for 
the case of log2(0)==null that a lot of calcite code needs to be changed, I am 
skeptical. I can even suggest that our handling of log2(0) should be stated in 
the document, and I feel that mysql handles this wrongly from the beginning. I 
studied presto and arrow-datafusion, and to be honest, they couldn't overcome 
this problem very well.



-- 
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...@calcite.apache.org

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

Reply via email to