From 3320fdce57e3d957d171935f2b9aa380f8d7dc31 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 17 May 2020 05:39:02 +0300 Subject: [PATCH] Fix error --- .../AggregateFunctionStatisticsSimple.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h b/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h index 3920489897c..96c07cc3d41 100644 --- a/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h +++ b/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h @@ -80,23 +80,28 @@ struct VarMoments readPODBinary(*this, buf); } - T NO_SANITIZE_UNDEFINED getPopulation() const + T getPopulation() const { + if (m[0] == 0) + return std::numeric_limits::quiet_NaN(); + /// Due to numerical errors, the result can be slightly less than zero, /// but it should be impossible. Trim to zero. return std::max(T{}, (m[2] - m[1] * m[1] / m[0]) / m[0]); } - T NO_SANITIZE_UNDEFINED getSample() const + T getSample() const { if (m[0] <= 1) return std::numeric_limits::quiet_NaN(); return std::max(T{}, (m[2] - m[1] * m[1] / m[0]) / (m[0] - 1)); } - T NO_SANITIZE_UNDEFINED getMoment3() const + T getMoment3() const { + if (m[0] == 0) + return std::numeric_limits::quiet_NaN(); // to avoid accuracy problem if (m[0] == 1) return 0; @@ -107,8 +112,10 @@ struct VarMoments ) / m[0]; } - T NO_SANITIZE_UNDEFINED getMoment4() const + T getMoment4() const { + if (m[0] == 0) + return std::numeric_limits::quiet_NaN(); // to avoid accuracy problem if (m[0] == 1) return 0;