diff --git a/base/base_tests/math_test.cpp b/base/base_tests/math_test.cpp index 78be4eccc3..4feb161c62 100644 --- a/base/base_tests/math_test.cpp +++ b/base/base_tests/math_test.cpp @@ -2,6 +2,7 @@ #include "../math.hpp" #include "../../std/limits.hpp" +#include UNIT_TEST(id) { @@ -68,22 +69,14 @@ namespace // Returns the next representable floating point value without using conversion to integer. template FloatT NextFloat(FloatT const x, int dir = 1) { - FloatT d = dir * numeric_limits::denorm_min(); - while (true) - { - FloatT y = x; - y += d; - if (x != y) - return y; - d *= 2; - } + return boost::math::float_advance(x, dir); } template void TestMaxULPs() { for (unsigned int logMaxULPs = 0; logMaxULPs <= 8; ++logMaxULPs) { - unsigned int const maxULPs = (logMaxULPs == 0 ? 0 : ((1 << logMaxULPs) - 1)); + unsigned int const maxULPs = (1 << logMaxULPs) - 1; for (int base = -1; base <= 1; ++base) { for (int dir = -1; dir <= 1; dir += 2) diff --git a/indexer/indexer_tests/mercator_test.cpp b/indexer/indexer_tests/mercator_test.cpp index 2589b6d4fe..fe951d02f8 100644 --- a/indexer/indexer_tests/mercator_test.cpp +++ b/indexer/indexer_tests/mercator_test.cpp @@ -11,8 +11,7 @@ UNIT_TEST(Mercator_Grid) { - double const eps = 0.0000001; - for (int lat = -85; lat <= 85; ++lat) + for (int lat = -86; lat <= 86; ++lat) { for (int lon = -180; lon <= 180; ++lon) { @@ -27,13 +26,6 @@ UNIT_TEST(Mercator_Grid) // x is actually lon unmodified. TEST_ALMOST_EQUAL(x, static_cast(lon), ()); - - if (lat == 0) - { - // TODO: Investigate, how to make Mercator transform more precise. - // Error is to large for TEST_ALMOST_EQUAL(y, 0.0, ()); - TEST_LESS(fabs(y), eps, (lat, y, lat1)); - } } } } diff --git a/indexer/mercator.hpp b/indexer/mercator.hpp index e86d59d848..452e26116e 100644 --- a/indexer/mercator.hpp +++ b/indexer/mercator.hpp @@ -43,13 +43,13 @@ struct MercatorBounds inline static double YToLat(double y) { - return my::RadToDeg(2.0 * atan(exp(my::DegToRad(y))) - math::pi / 2.0); + return my::RadToDeg(2.0 * atan(tanh(0.5 * my::DegToRad(y)))); } inline static double LatToY(double lat) { - lat = my::clamp(lat, -86.0, 86.0); - double const res = my::RadToDeg(log(tan(my::DegToRad(45.0 + lat * 0.5)))); + double const sinx = sin(my::DegToRad(my::clamp(lat, -86.0, 86.0))); + double const res = my::RadToDeg(0.5 * log((1.0 + sinx) / (1.0 - sinx))); return ClampY(res); }