trying to fix different types of *

This commit is contained in:
myrrc 2020-12-23 17:18:38 +03:00
parent fec0a59082
commit fcfe76d703

View File

@ -802,20 +802,26 @@ class FunctionBinaryArithmetic : public IFunction
if constexpr (IsDataTypeDecimal<RightDataType> && is_division) if constexpr (IsDataTypeDecimal<RightDataType> && is_division)
return right.getScaleMultiplier(); // the division impl uses only the scale_a return right.getScaleMultiplier(); // the division impl uses only the scale_a
else if constexpr (result_is_decimal) else if constexpr (result_is_decimal)
return type.scaleFactorFor(left, is_multiply); // scale_a = 1 is result is decimal
else if constexpr (left_is_decimal) // needed for e.g. multiply(Decimal, Float) to scale the arguments return is_multiply ? 1 : type.scaleFactorFor(left, false);
// scale multiplier = 10^scale, so we need to get this value divided by 10^0 -> 2nd arg is 0 as else if constexpr (left_is_decimal)
// the convertTo basically divides the given value on the second arg. {
return 1 / DecimalUtils::convertTo<ResultType>(left.getScaleMultiplier(), 0); const ResultType scale = DecimalUtils::convertTo<ResultType>(left.getScaleMultiplier(), 0);
// if const, the scale needs to be inverted
return !col_left_const ? scale : (1 / scale);
}
else else
return 1; // the default value which won't cause any re-scale return 1; // the default value which won't cause any re-scale
}(); }();
const ResultType scale_b = [&] { const ResultType scale_b = [&] {
if constexpr (result_is_decimal) if constexpr (result_is_decimal)
return type.scaleFactorFor(right, is_multiply || is_division); return is_multiply ? 1 : type.scaleFactorFor(right, true);
else if constexpr (right_is_decimal) else if constexpr (right_is_decimal)
return 1 / DecimalUtils::convertTo<ResultType>(right.getScaleMultiplier(), 0); {
const ResultType scale = DecimalUtils::convertTo<ResultType>(right.getScaleMultiplier(), 0);
return !col_right_const ? scale : (1 / scale);
}
else else
return 1; return 1;
}(); }();