From 98d9ac00e459e70ed60bd4509165cec6f109ce4e Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 4 Oct 2017 18:10:47 +0300 Subject: [PATCH] Fixing DoubleToUint32() and Uint32ToDouble(). --- coding/point_to_integer.cpp | 8 ++++++-- routing_common/transit_serdes.hpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/coding/point_to_integer.cpp b/coding/point_to_integer.cpp index f1a9044134..002cf98b3d 100644 --- a/coding/point_to_integer.cpp +++ b/coding/point_to_integer.cpp @@ -73,11 +73,15 @@ m2::RectD Int64ToRect(std::pair const & p, uint32_t coordBits) uint32_t DoubleToUint32(double x, double min, double max, uint32_t coordBits) { + ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); + ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); x = my::clamp(x, min, max); - return static_cast(0.5 + (x - min) / (max - min) * ((1 << coordBits) - 1)); + return static_cast(0.5 + (x - min) / (max - min) * bits::GetFullMask(static_cast(coordBits))); } double Uint32ToDouble(uint32_t x, double min, double max, uint32_t coordBits) { - return min + static_cast(x) * (max - min) / ((1 << coordBits) - 1); + ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); + ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); + return min + static_cast(x) * (max - min) / bits::GetFullMask(static_cast(coordBits)); } diff --git a/routing_common/transit_serdes.hpp b/routing_common/transit_serdes.hpp index 4d31b04131..fdc49ed4d2 100644 --- a/routing_common/transit_serdes.hpp +++ b/routing_common/transit_serdes.hpp @@ -30,7 +30,7 @@ namespace transit // Let us assume that it takes less than 10^7 seconds (115 days) to get from one station to a neighboring one. double constexpr kMinDoubleAtTransit = kInvalidWeight; double constexpr kMaxDoubleAtTransit = 10000000.0; -uint32_t constexpr kDoubleBits = 31; +uint32_t constexpr kDoubleBits = 32; template class Serializer