@SuppressWarnings("unchecked")
    public static <D extends Number> D result(D num1, Number num2, Operator operator) {
        BigDecimal d1 = toBigDecimal(num1);
        BigDecimal d2 = toBigDecimal(num2);
        if (operator == Ops.ADD) {
            return MathUtils.cast(d1.add(d2), (Class<D>) num1.getClass());
        } else if (operator == Ops.SUB) {
            return MathUtils.cast(d1.subtract(d2), (Class<D>) num1.getClass());
        } else if (operator == Ops.MULT) {
            return MathUtils.cast(d1.multiply(d2), (Class<D>) num1.getClass());
        } else if (operator == Ops.DIV) {
            return MathUtils.cast(d1.divide(d2), (Class<D>) num1.getClass());
        } else {
            throw new IllegalArgumentException(operator.toString());
        }
    }
MathUtils provides Math related functionality

@author tiwe
querydsl-core/src/main/java/com/querydsl/core/util/MathUtils.java