raminqaf commented on code in PR #28765:
URL: https://github.com/apache/flink/pull/28765#discussion_r3601567845


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala:
##########
@@ -233,12 +233,14 @@ object CodeGenUtils {
       value match {
         case JFloat.NEGATIVE_INFINITY => "java.lang.Float.NEGATIVE_INFINITY"
         case JFloat.POSITIVE_INFINITY => "java.lang.Float.POSITIVE_INFINITY"
+        case f: JFloat if f.isNaN => "java.lang.Float.NaN"

Review Comment:
   I have tried this and it does not work. The case doesn't hit. I think there 
something with equality of `NaN` here. I asked AI for an explanation: 
   ```
   JFloat.NaN is java.lang.Float.NaN, i.e. a primitive float, so that == is 
Scala's numeric equality, which follows IEEE 754 primitive semantics. And by 
IEEE 754:
                                                                                
                                                                                
    
     NaN == NaN   →   false  
     
   Note this is not java.lang.Float.equals. That method special-cases NaN via 
bit comparison (Float.valueOf(NaN).equals(Float.valueOf(NaN)) is true), but 
Scala's 
     == on numbers does not dispatch to it — it uses primitive == semantics. So 
the pattern silently never matches.
   ```



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala:
##########
@@ -233,12 +233,14 @@ object CodeGenUtils {
       value match {
         case JFloat.NEGATIVE_INFINITY => "java.lang.Float.NEGATIVE_INFINITY"
         case JFloat.POSITIVE_INFINITY => "java.lang.Float.POSITIVE_INFINITY"
+        case f: JFloat if f.isNaN => "java.lang.Float.NaN"
         case _ => value.toString + "f"
       }
     case _: JDouble =>
       value match {
         case JDouble.NEGATIVE_INFINITY => "java.lang.Double.NEGATIVE_INFINITY"
         case JDouble.POSITIVE_INFINITY => "java.lang.Double.POSITIVE_INFINITY"
+        case d: JDouble if d.isNaN => "java.lang.Double.NaN"

Review Comment:
   See https://github.com/apache/flink/pull/28765#discussion_r3601567845



-- 
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: [email protected]

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

Reply via email to