From fec0a590829d80f6f33260c3e7263bfc5281d8bf Mon Sep 17 00:00:00 2001 From: myrrc Date: Wed, 23 Dec 2020 16:57:11 +0300 Subject: [PATCH] transfered scale factor calc for multiply from the impl --- src/Functions/FunctionBinaryArithmetic.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Functions/FunctionBinaryArithmetic.h b/src/Functions/FunctionBinaryArithmetic.h index 439e554566c..64dfb9e2691 100644 --- a/src/Functions/FunctionBinaryArithmetic.h +++ b/src/Functions/FunctionBinaryArithmetic.h @@ -311,12 +311,12 @@ public: static void NO_INLINE process(const A & a, const B & b, ResultContainerType & c, NativeResultType scale_a, NativeResultType scale_b) { - if constexpr(op_case == OpCase::LeftConstant) static_assert(!IsDecimalNumber); - if constexpr(op_case == OpCase::RightConstant) static_assert(!IsDecimalNumber); + if constexpr (op_case == OpCase::LeftConstant) static_assert(!IsDecimalNumber); + if constexpr (op_case == OpCase::RightConstant) static_assert(!IsDecimalNumber); size_t size; - if constexpr(op_case == OpCase::LeftConstant) + if constexpr (op_case == OpCase::LeftConstant) size = b.size(); else size = a.size(); @@ -342,12 +342,10 @@ public: return; } } - else if constexpr(is_multiply) + else if constexpr (is_multiply) { if (scale_a != 1) { - scale_a = 1 / scale_a; // see scale_a initialization for detail - for (size_t i = 0; i < size; ++i) c[i] = applyScaled( unwrap(a, i), @@ -357,8 +355,6 @@ public: } else if (scale_b != 1) { - scale_b = 1 / scale_b; - for (size_t i = 0; i < size; ++i) c[i] = applyScaled( unwrap(a, i), @@ -423,7 +419,7 @@ private: template static auto unwrap(const auto& elem, size_t i) { - if constexpr(op_case == target) + if constexpr (op_case == target) return undec(elem); else return undec(elem[i]); @@ -807,12 +803,10 @@ class FunctionBinaryArithmetic : public IFunction return right.getScaleMultiplier(); // the division impl uses only the scale_a else if constexpr (result_is_decimal) return type.scaleFactorFor(left, is_multiply); - else if constexpr(left_is_decimal) // needed for e.g. multiply(Decimal, Float) to scale the arguments + else if constexpr (left_is_decimal) // needed for e.g. multiply(Decimal, Float) to scale the arguments // scale multiplier = 10^scale, so we need to get this value divided by 10^0 -> 2nd arg is 0 as // the convertTo basically divides the given value on the second arg. - // Note we are using the scale factor instead of 1 / scale factor, it will be correctly processed in - // the impl. - return DecimalUtils::convertTo(left.getScaleMultiplier(), 0); + return 1 / DecimalUtils::convertTo(left.getScaleMultiplier(), 0); else return 1; // the default value which won't cause any re-scale }(); @@ -820,8 +814,8 @@ class FunctionBinaryArithmetic : public IFunction const ResultType scale_b = [&] { if constexpr (result_is_decimal) return type.scaleFactorFor(right, is_multiply || is_division); - else if constexpr(right_is_decimal) - return DecimalUtils::convertTo(right.getScaleMultiplier(), 0); + else if constexpr (right_is_decimal) + return 1 / DecimalUtils::convertTo(right.getScaleMultiplier(), 0); else return 1; }();