public static int doubleCompare(double a, double b)
    {
        // these three ifs can only be true if neither value is NaN
        if (a < b) {
            return -1;
        }
        if (a > b) {
            return 1;
        }
        // this check ensure doubleCompare(+0, -0) will return 0
        // if we just did doubleToLongBits comparison, then they
        // would not compare as equal
        if (a == b) {
            return 0;
        }

        // this ensures that doubleCompare(NaN, NaN) will return 0
        // doubleToLongBits converts all NaNs to the same representation
        long aBits = doubleToLongBits(a);
        long bBits = doubleToLongBits(b);
        return Long.compare(aBits, bBits);
    }
@Test
    public void testDoubleCompare()
    {
        assertEquals(doubleCompare(0, Double.parseDouble("-0")), 0);
        assertEquals(doubleCompare(Double.NaN, Double.NaN), 0);
        //0x7ff8123412341234L is a different representation of NaN
        assertEquals(doubleCompare(Double.NaN, longBitsToDouble(0x7ff8123412341234L)), 0);
    }