public static Integer compare(final Number a, final Number b) {
        // handle one or both null
        if (a == null || b == null)
            return a == b ? 0 : (a == null ? -1 : 1);

        // handle one or both NaN
        if (eitherAreNaN(a, b))
            return (bothAreNaN(a, b)) ? 0 : isNaN(a) ? 1 : -1;

        final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
        return getHelper(clazz).cmp.apply(a, b);
    }
Compares two numbers. Follows orderability semantics for NaN, which places NaN after +Inf.

<pre>
    a = 4, b = 2 -> 1
    a = 2, b = 4 -> -1
    a = null, b = 1 -> -1
    a = 1, b = null -> 1
    a = null, b = null -> 0
    a = NaN, b = NaN -> 0
    a = NaN, b = Inf -> 1
</pre>
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java