Skip to content

Commit

Permalink
Fixed bug where normalise_angle would stall when passed very large nu…
Browse files Browse the repository at this point in the history
…mbers.
  • Loading branch information
jhaiduce committed Jan 22, 2024
1 parent 2ba2a0d commit 7c54178
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/eckit/geometry/CoordinateHelpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <limits>
#include <sstream>
#include <cmath>

#include "eckit/exception/Exceptions.h"
#include "eckit/geometry/CoordinateHelpers.h"
Expand All @@ -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.);
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 7c54178

Please sign in to comment.