From 1ba67ea8a1aa3964677ebb534cf1837b691f1fe9 Mon Sep 17 00:00:00 2001 From: Artem Zuikov Date: Tue, 15 Sep 2020 13:31:15 +0300 Subject: [PATCH] Improve DecimalBinaryOperation specializations (#14743) --- src/Functions/FunctionBinaryArithmetic.h | 201 +++++++++-------------- src/Functions/intDiv.cpp | 2 +- src/Functions/modulo.cpp | 2 +- 3 files changed, 79 insertions(+), 126 deletions(-) diff --git a/src/Functions/FunctionBinaryArithmetic.h b/src/Functions/FunctionBinaryArithmetic.h index bbac58a92c..bbb08c4068 100644 --- a/src/Functions/FunctionBinaryArithmetic.h +++ b/src/Functions/FunctionBinaryArithmetic.h @@ -65,7 +65,7 @@ namespace ErrorCodes */ template -struct BinaryOperationImplBase +struct BinaryOperation { using ResultType = ResultType_; static const constexpr bool allow_fixed_string = false; @@ -167,16 +167,24 @@ struct FixedStringOperationImpl template -struct BinaryOperationImpl : BinaryOperationImplBase +struct BinaryOperationImpl : BinaryOperation { }; +template +inline constexpr const auto & undec(const T & x) +{ + if constexpr (IsDecimalNumber) + return x.value; + else + return x; +} /// Binary operations for Decimals need scale args /// +|- scale one of args (which scale factor is not 1). ScaleR = oneof(Scale1, Scale2); /// * no agrs scale. ScaleR = Scale1 + Scale2; /// / first arg scale. ScaleR = Scale1 (scale_a = DecimalType::getScale()). -template typename Operation, typename ResultType_, bool _check_overflow = true> +template