From b7e94b487c91674064b9e3bf7d59ed959953f586 Mon Sep 17 00:00:00 2001 From: myrrc Date: Tue, 24 Nov 2020 17:29:30 +0300 Subject: [PATCH] fixed scale calc, again --- src/AggregateFunctions/AggregateFunctionAvg.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionAvg.h b/src/AggregateFunctions/AggregateFunctionAvg.h index c3552883b8c..fca9df9dd98 100644 --- a/src/AggregateFunctions/AggregateFunctionAvg.h +++ b/src/AggregateFunctions/AggregateFunctionAvg.h @@ -37,15 +37,15 @@ struct AvgFraction { if constexpr (IsDecimalNumber && IsDecimalNumber) { - const UInt32 result_scale = std::max(num_scale, denom_scale); + // According to the docs, num(S1) / denom(S2) would have scale S1 if constexpr (std::is_same_v && std::is_same_v) ///Special case as Decimal256 / Decimal128 = compile error (as Decimal128 is not parametrized by a wide ///int), but an __int128 instead return DecimalUtils::convertTo( - numerator / (denominator.template convertTo()), result_scale); + numerator / (denominator.template convertTo()), num_scale); else - return DecimalUtils::convertTo(numerator / denominator, result_scale); + return DecimalUtils::convertTo(numerator / denominator, num_scale); } /// Numerator is always casted to Float64 to divide correctly if the denominator is not Float64.