public static int compare()

in velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java [466:507]


    public static int compare (Number op1, Number op2) {

        int calcBase = findCalculationBase( op1, op2);
        switch (calcBase) {
            case BASE_BIGINTEGER:
                return toBigInteger( op1 ).compareTo( toBigInteger( op2 ));
            case BASE_LONG:
                long l1 = op1.longValue();
                long l2 = op2.longValue();
                if (l1 < l2) {
                    return -1;
                }
                if (l1 > l2) {
                    return 1;
                }
                return 0;
            case BASE_FLOAT:
                float f1 = op1.floatValue();
                float f2 = op2.floatValue();
                if (f1 < f2) {
                    return -1;
                }
                if (f1 > f2) {
                    return 1;
                }
                return 0;
            case BASE_DOUBLE:
                double d1 = op1.doubleValue();
                double d2 = op2.doubleValue();
                if (d1 < d2) {
                    return -1;
                }
                if (d1 > d2) {
                    return 1;
                }
                return 0;

            // Default is BigDecimal operation
            default:
                return toBigDecimal( op1 ).compareTo( toBigDecimal ( op2 ));
        }
    }