diff --git a/src/Functions/FunctionBinaryArithmetic.h b/src/Functions/FunctionBinaryArithmetic.h index 276b2e11fb1..756a6c2e4d3 100644 --- a/src/Functions/FunctionBinaryArithmetic.h +++ b/src/Functions/FunctionBinaryArithmetic.h @@ -348,6 +348,29 @@ struct DecimalBinaryOperation return; } } + else if constexpr(is_multiply && (!is_decimal_a || !is_decimal_b)) // BUG very bad solution + { + if (scale_a != 1) + { + for (size_t i = 0; i < size; ++i) + if constexpr(IsDecimalNumber) + c[i] = apply(a, undec(a[i])) / DecimalUtils::scaleMultiplier(scale_a); + else + c[i] = apply(a, undec(a[i])) / DecimalUtils::scaleMultiplier(scale_a); + return; + } + else if (scale_b != 1) + { + for (size_t i = 0; i < size; ++i) + if constexpr(IsDecimalNumber) + c[i] = apply(a, undec(b[i])) / DecimalUtils::scaleMultiplier(scale_b); + else + c[i] = apply(a, undec(b[i])) / DecimalUtils::scaleMultiplier(scale_b); + + return; + } + } + else if constexpr (is_division && is_decimal_b) { for (size_t i = 0; i < size; ++i) diff --git a/tests/queries/0_stateless/01603_decimal_mult_float.reference b/tests/queries/0_stateless/01603_decimal_mult_float.reference index 08e0fc89922..c25beb42a27 100644 --- a/tests/queries/0_stateless/01603_decimal_mult_float.reference +++ b/tests/queries/0_stateless/01603_decimal_mult_float.reference @@ -3,10 +3,10 @@ 0.00012000000000000002 150.16500000000002 7.775900000000001 -56.622689999999995 -598.8376688440277 +56622.689999999995 +5.988376688440276 2.9941884322906844 1.641386318314034 1.641386318314034 -1.6413863211679272 -1.6413863211679272 +1.6413863192433382 +1.6413863192433382 diff --git a/tests/queries/0_stateless/01603_decimal_mult_float.sql b/tests/queries/0_stateless/01603_decimal_mult_float.sql index 8de35f0b3f5..407fe3649ec 100644 --- a/tests/queries/0_stateless/01603_decimal_mult_float.sql +++ b/tests/queries/0_stateless/01603_decimal_mult_float.sql @@ -14,7 +14,9 @@ INSERT INTO test01603(f64) SELECT 1 / (number + 1) FROM system.numbers LIMIT 100 SELECT sum(d * 1.1) FROM test01603; SELECT sum(8.01 * d) FROM test01603; SELECT sum(f64 * toDecimal64(80, 2)) FROM test01603; -SELECT sum(toDecimal64(0.4, 2) * f32) FROM test01603; +SELECT sum(toDecimal64(40, 2) * f32) FROM test01603; +SELECT sum(f64 * toDecimal64(0.1, 2)) FROM test01603; +SELECT sum(toDecimal64(0.3, 2) * f32) FROM test01603; SELECT sum(f64 * d) FROM test01603; SELECT sum(d * f64) FROM test01603;