aboutsummaryrefslogtreecommitdiff
path: root/src/adjlon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/adjlon.cpp')
-rw-r--r--src/adjlon.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/adjlon.cpp b/src/adjlon.cpp
new file mode 100644
index 00000000..784a90aa
--- /dev/null
+++ b/src/adjlon.cpp
@@ -0,0 +1,20 @@
+/* reduce argument to range +/- PI */
+#include <math.h>
+#include "projects.h"
+
+double adjlon (double lon) {
+ /* Let lon slightly overshoot, to avoid spurious sign switching at the date line */
+ if (fabs (lon) < M_PI + 1e-12)
+ return lon;
+
+ /* adjust to 0..2pi range */
+ lon += M_PI;
+
+ /* remove integral # of 'revolutions'*/
+ lon -= M_TWOPI * floor(lon / M_TWOPI);
+
+ /* adjust back to -pi..pi range */
+ lon -= M_PI;
+
+ return lon;
+}