From 4a477848473e5018b2f1bf0334ef6efc6136338d Mon Sep 17 00:00:00 2001 From: Peter Saunderson Date: Wed, 21 Feb 2024 21:22:38 +0000 Subject: [PATCH] fix sign of 0 is ignored --- src/Longitude.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Longitude.cpp b/src/Longitude.cpp index de019770..062bb752 100644 --- a/src/Longitude.cpp +++ b/src/Longitude.cpp @@ -83,12 +83,17 @@ const char *Longitude::formatString(char *targetBuffer, const char *format, long secs = secs - degs * 3600; long mins = secs / 60; secs = secs - mins * 60; + char sgn; if (totalSeconds < 0) { - degs = -degs; + sgn = '-'; + } + else + { + sgn = '+'; } - return formatStringImpl(targetBuffer, format, '\0', degs, mins, secs); + return formatStringImpl(targetBuffer, format, sgn, degs, mins, secs); } const char *Longitude::formatStringForMeade(char *targetBuffer) const @@ -102,15 +107,17 @@ const char *Longitude::formatStringForMeade(char *targetBuffer) const secs = secs - mins * 60; LOG(DEBUG_MEADE, "[LONGITUDE] Degs is %l, Mins is %l", degs, mins); - // Since internal storage is actual longitude, Meade is negated + char sgn; if (totalSeconds > 0) { - // Since we already inverted it when it was negative (by using ABS a few - // lines above here), we only invert it if it is positive. - degs = -degs; + sgn = '-'; + } + else + { + sgn = '+'; } LOG(DEBUG_MEADE, "[LONGITUDE] Inverted Degs, now %l, Mins is %l", degs, mins); - return formatStringImpl(targetBuffer, "{+}{d}*{m}", '\0', degs, mins, secs); + return formatStringImpl(targetBuffer, "{d}*{m}", sgn, degs, mins, secs); }