normalise_angle stalls when passed very large numbers
jhaiduce opened this issue · comments
What happened?
The function eckit::geometry::normalise_angle
will stall when passed very large numbers.
This is because the normalization is accomplished using a loop which repeatedly subtracts 360 from the input angle until reaching a value in the range [minimum, minimum+360). Thus the loop runs a/360 times. For very large inputs, it effectively becomes an infinite loop.
What are the steps to reproduce the bug?
For example, the following program will never exit:
#include "eckit/geometry/CoordinateHelpers.h"
int main(int argc, char** argv) {
double a=1e36;
a=eckit::geometry::normalise_angle(a,0);
}
Version
I found the bug in v. 1.24.4, but the bug was first introduced in commit f8d15f2.
Platform (OS and architecture)
I was testing on MacOS 12.6.1 running on an M1 processor, but this bug should be reproducible on all platforms.
Relevant log output
No response
Accompanying data
No response
Organisation
US Naval Research Laboratory