From 7c54178aee6fd6dcca200da1eb98e49d0ea07187 Mon Sep 17 00:00:00 2001 From: John Haiducek Date: Mon, 22 Jan 2024 14:11:43 -0500 Subject: [PATCH] Fixed bug where normalise_angle would stall when passed very large numbers. --- src/eckit/geometry/CoordinateHelpers.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/eckit/geometry/CoordinateHelpers.cc b/src/eckit/geometry/CoordinateHelpers.cc index 48ab93117..d8635d4ca 100644 --- a/src/eckit/geometry/CoordinateHelpers.cc +++ b/src/eckit/geometry/CoordinateHelpers.cc @@ -7,6 +7,7 @@ #include #include +#include #include "eckit/exception/Exceptions.h" #include "eckit/geometry/CoordinateHelpers.h" @@ -16,14 +17,12 @@ namespace eckit::geometry { //---------------------------------------------------------------------------------------------------------------------- -double normalise_angle(double a, const double minimum) { - while (a < minimum) { - a += 360.; - } - while (a >= minimum + 360.) { - a -= 360.; - } - return a; +inline double modulo(const double a, const double b) { + return a-b*std::floor(a/b); +} + +double normalise_angle(const double a, const double minimum) { + return minimum + modulo(a-minimum, 360.); } //----------------------------------------------------------------------------------------------------------------------