public static int nanSafeCompareDoubles(double x, double y) {
        boolean xIsNan = java.lang.Double.isNaN(x);
        boolean yIsNan = java.lang.Double.isNaN(y);
        if ((xIsNan && yIsNan) || (x == y)) return 0;
        else if (xIsNan) return 1;
        else if (yIsNan) return -1;
        else if (x > y) return 1;
        else return -1;
    }
NaN-safe version of [[java.lang.DOUBLE.compare()]] which allows NaN values to be compared
according to semantics where NaN == NaN and NaN bigger than any non-NaN double.
indexr-query-opt/src/main/java/org/apache/spark/util/Utils.java