@SuppressWarnings("unchecked")
    public static <D extends Number> D sum(D num1, Number num2) {
        BigDecimal res = toBigDecimal(num1).add(toBigDecimal(num2));
        return MathUtils.cast(res, (Class<D>) num1.getClass());
    }
MathUtils provides Math related functionality

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