From 3881ead8e58a6366edcb9e46b2fddfa0eb18b8e4 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Sun, 5 Jun 2016 14:10:36 +0200 Subject: [PATCH] Fix rounding issue due to non-associative floating arithmetic Failing test features/car/traffic_turn_penalties.feature:33 Tables were not identical: from | to | route | speed | time | a | h | ad,dhk,dhk | 63 km/h | 11.5s +-1 | | i | g | fim,fg,fg | 59 km/h | 12s +-1 | | (-) a | (-) e | (-) ad,de,de | (-) 57 km/h | (-) 12.5s +-1 | | (+) a | (+) e | (+) ad,de,de | (+) 58 km/h | (+) 12.5s +-1 | | c | g | cd,de,ef,fg,fg | 63 km/h | 23s +-1 | | p | g | mp,fim,fg,fg | 61 km/h | 23.5s +-1 | | a | l | ad,dhk,kl,kl | 60 km/h | 24s +-1 | | l | e | kl,dhk,de,de | 59 km/h | 24.5s +-1 | | g | n | fg,fim,mn,mn | 57 km/h | 25s +-1 | --- src/util/coordinate_calculation.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 7dafb784a..89266feaa 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -276,10 +276,13 @@ Coordinate interpolateLinear(double factor, const Coordinate from, const Coordin { BOOST_ASSERT(0 <= factor && factor <= 1.0); - FixedLongitude interpolated_lon(((1. - factor) * static_cast(from.lon)) + - (factor * static_cast(to.lon))); - FixedLatitude interpolated_lat(((1. - factor) * static_cast(from.lat)) + - (factor * static_cast(to.lat))); + const auto from_lon = static_cast(from.lon); + const auto from_lat = static_cast(from.lat); + const auto to_lon = static_cast(to.lon); + const auto to_lat = static_cast(to.lat); + + FixedLongitude interpolated_lon(from_lon + factor * (to_lon - from_lon)); + FixedLatitude interpolated_lat(from_lat + factor * (to_lat - from_lat)); return {std::move(interpolated_lon), std::move(interpolated_lat)}; }