Remove sum_error function

This commit is contained in:
Vissarion Fisikopoulos 2021-07-05 13:25:27 +03:00
parent 6f31aeee3a
commit f940c16fd6
3 changed files with 13 additions and 25 deletions

View File

@ -36,6 +36,7 @@
#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/math.hpp>
#include <boost/geometry/util/precise_math.hpp>
#include <boost/geometry/util/series_expansion.hpp>
#include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
@ -51,16 +52,20 @@ namespace boost { namespace geometry { namespace math {
template<typename T>
inline T difference_angle(T const& x, T const& y, T& e)
{
T t, d = math::sum_error(std::remainder(-x, T(360)), std::remainder(y, T(360)), t);
auto res1 = boost::geometry::detail::precise_math::two_sum(
std::remainder(-x, T(360)), std::remainder(y, T(360)));
normalize_azimuth<degree, T>(d);
normalize_azimuth<degree, T>(res1[0]);
// Here y - x = d + t (mod 360), exactly, where d is in (-180,180] and
// abs(t) <= eps (eps = 2^-45 for doubles). The only case where the
// addition of t takes the result outside the range (-180,180] is d = 180
// and t > 0. The case, d = -180 + eps, t = -eps, can't happen, since
// sum_error would have returned the exact result in such a case (i.e., given t = 0).
return math::sum_error(d == 180 && t > 0 ? -180 : d, t, e);
auto res2 = boost::geometry::detail::precise_math::two_sum(
res1[0] == 180 && res1[1] > 0 ? -180 : res1[0], res1[1]);
e = res2[1];
return res2[0];
}
}}} // namespace boost::geometry::math

View File

@ -4,12 +4,13 @@
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
// This file was modified by Oracle on 2014-2020.
// Modifications copyright (c) 2014-2020, Oracle and/or its affiliates.
// This file was modified by Oracle on 2014-2021.
// Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Adeel Ahmad, as part of Google Summer of Code 2018 program
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Contributed and/or modified by Adeel Ahmad, as part of Google Summer of Code 2018 program
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
@ -847,24 +848,6 @@ inline T round_angle(T const& x) {
return x < 0 ? -y : y;
}
/*!
\brief The error-free sum of two numbers.
*/
template<typename T>
inline T sum_error(T const& u, T const& v, T& t)
{
volatile T s = u + v;
volatile T up = s - v;
volatile T vpp = s - up;
up -= u;
vpp -= v;
t = -(up + vpp);
return s;
}
/*!
\brief Evaluate the polynomial in x using Horner's method.
*/

View File

@ -51,7 +51,7 @@ expected_results_small_angles expected_small_angles[] =
{ 20003931.45862544700503349304, -0.00000000000000000000, 180.00000000000000000000, 67125.61229850351810455322266, -1.00000000000000000000 },
},{
{ 180, 0 },{ 1e-20, 0 },
{ 20003931.45862544700503349304, -0.00000000000000000000, 180.00000000000000000000, 67125.61229850351810455322266, -1.00000000000000000000 },
{ 20003931.45862544700503349304, -9.4938222885831061895e-19, 180.00000000000000000000, 67125.61229850351810455322266, -1.00000000000000000000 },
},{
{ 180, 0 },{ 1e-10, 0 },
{ 20003931.45862544700503349304, -9.501793528220011062168943853e-09, -179.9999999904981962117744843, 67125.61229850351810455322266, -1 },