From e089abd4625bc85d930d521acb7995605ca14096 Mon Sep 17 00:00:00 2001 From: m-with-m Date: Mon, 14 Dec 2020 18:10:11 +0300 Subject: [PATCH] [coding] Uint32ToDouble minor fix. --- coding/point_coding.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coding/point_coding.cpp b/coding/point_coding.cpp index 9b89ed203c..a18c07f46e 100644 --- a/coding/point_coding.cpp +++ b/coding/point_coding.cpp @@ -30,7 +30,9 @@ double Uint32ToDouble(uint32_t x, double min, double max, uint8_t coordBits) { ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); - return min + static_cast(x) * (max - min) / bits::GetFullMask(coordBits); + auto const res = min + static_cast(x) * (max - min) / bits::GetFullMask(coordBits); + // Clamp to avoid floating point calculation errors. + return base::Clamp(res, min, max); } m2::PointU PointDToPointU(double x, double y, uint8_t coordBits)