You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/12/04 20:34:02 UTC

[GitHub] [spark] dongjoon-hyun commented on a change in pull request #26761: [SPARK-30009][CORE][SQL][FOLLOWUP] Remove OrderingUtil and Utils.nanSafeCompare{Doubles, Floats} and use java.lang.{Double, Float}.compare directly

dongjoon-hyun commented on a change in pull request #26761: [SPARK-30009][CORE][SQL][FOLLOWUP] Remove OrderingUtil and Utils.nanSafeCompare{Doubles,Floats} and use java.lang.{Double,Float}.compare directly
URL: https://github.com/apache/spark/pull/26761#discussion_r353968055
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/util/Utils.scala
 ##########
 @@ -1744,34 +1744,6 @@ private[spark] object Utils extends Logging {
     hashAbs
   }
 
-  /**
-   * NaN-safe version of `java.lang.Double.compare()` which allows NaN values to be compared
-   * according to semantics where NaN == NaN and NaN is greater than any non-NaN double.
-   */
-  def nanSafeCompareDoubles(x: Double, y: Double): Int = {
-    val xIsNan: Boolean = java.lang.Double.isNaN(x)
-    val yIsNan: Boolean = java.lang.Double.isNaN(y)
-    if ((xIsNan && yIsNan) || (x == y)) 0
-    else if (xIsNan) 1
-    else if (yIsNan) -1
-    else if (x > y) 1
-    else -1
-  }
-
-  /**
-   * NaN-safe version of `java.lang.Float.compare()` which allows NaN values to be compared
-   * according to semantics where NaN == NaN and NaN is greater than any non-NaN float.
-   */
 
 Review comment:
   Yes. I also checked that `compare` handles different NaN values correctly via `floatToIntBits`, too. (Refer #23851)
   ```
       public static int compare(float f1, float f2) {
           if (f1 < f2)
               return -1;           // Neither val is NaN, thisVal is smaller
           if (f1 > f2)
               return 1;            // Neither val is NaN, thisVal is larger
   
           // Cannot use floatToRawIntBits because of possibility of NaNs.
           int thisBits    = Float.floatToIntBits(f1);
           int anotherBits = Float.floatToIntBits(f2);
   
           return (thisBits == anotherBits ?  0 : // Values are equal
                   (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
                    1));                          // (0.0, -0.0) or (NaN, !NaN)
       }
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org