From eb881d2957d426dd2d43bd3a6a7fe77121cf71ea Mon Sep 17 00:00:00 2001 From: Charles Karney Date: Sat, 13 Mar 2021 09:28:00 -0500 Subject: Update geodesic routines from GeographicLib 1.52 Be more aggressive in preventing negative s12 and m12 for short lines. Initialize reference argument to remquo. --- src/geodesic.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/geodesic.c') diff --git a/src/geodesic.c b/src/geodesic.c index 53ec9ed6..d5b22ac6 100644 --- a/src/geodesic.c +++ b/src/geodesic.c @@ -18,7 +18,7 @@ * * See the comments in geodesic.h for documentation. * - * Copyright (c) Charles Karney (2012-2020) and licensed + * Copyright (c) Charles Karney (2012-2021) and licensed * under the MIT/X11 License. For more information, see * https://geographiclib.sourceforge.io/ */ @@ -164,7 +164,7 @@ static real AngRound(real x) { static void sincosdx(real x, real* sinx, real* cosx) { /* In order to minimize round-off errors, this function exactly reduces * the argument to the range [-45, 45] before converting it to radians. */ - real r, s, c; int q; + real r, s, c; int q = 0; r = remquo(x, (real)(90), &q); /* now abs(r) <= 45 */ r *= degree; @@ -797,7 +797,9 @@ static real geod_geninverse_int(const struct geod_geodesic* g, * not a shortest path. */ if (sig12 < 1 || m12x >= 0) { /* Need at least 2, to handle 90 0 90 180 */ - if (sig12 < 3 * tiny) + if (sig12 < 3 * tiny || + // Prevent negative s12 or m12 for short lines + (sig12 < tol0 && (s12x < 0 || m12x < 0))) sig12 = m12x = s12x = 0; m12x *= g->b; s12x *= g->b; @@ -868,7 +870,6 @@ static real geod_geninverse_int(const struct geod_geodesic* g, slam12, clam12, &salp2, &calp2, &sig12, &ssig1, &csig1, &ssig2, &csig2, &eps, &domg12, numit < maxit1, &dv, Ca); - /* 2 * tol0 is approximately 1 ulp for a number in [0, pi]. */ /* Reversed test to allow escape with NaNs */ if (tripb || !(fabs(v) >= (tripn ? 8 : 1) * tol0)) break; /* Update bracketing values */ -- cgit v1.2.3