summaryrefslogtreecommitdiff
path: root/gpsd.h-tail
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2015-02-11 15:29:07 -0800
committerGary E. Miller <gem@rellim.com>2015-02-11 15:30:51 -0800
commita9eb0225e68d03c8feb3455cac606426b7502feb (patch)
tree7bdccbe80a50d02f49498cd3e4b62d1c61c50e45 /gpsd.h-tail
parent1b6b651d327efc7210a82ea6d7b48af7acb26c0d (diff)
downloadgpsd-a9eb0225e68d03c8feb3455cac606426b7502feb.tar.gz
Fix TS_NORM for negative numbers.
Whoops, I thought I commited this last week. Fixes display of -0.000000001 as -1.999999999 This fixes a lot of PPS glitches.
Diffstat (limited to 'gpsd.h-tail')
-rw-r--r--gpsd.h-tail22
1 files changed, 16 insertions, 6 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail
index bf323230..9c03decf 100644
--- a/gpsd.h-tail
+++ b/gpsd.h-tail
@@ -886,12 +886,22 @@ extern void pps_early_init(struct gps_context_t *);
/* normalize a timespec */
#define TS_NORM(ts) \
do { \
- if ( 1000000000 <= (ts)->tv_nsec ) { \
- (ts)->tv_nsec -= 1000000000; \
- (ts)->tv_sec++; \
- } else if ( 0 > (ts)->tv_nsec ) { \
- (ts)->tv_nsec += 1000000000; \
- (ts)->tv_sec--; \
+ if ( ( 0 > (ts)->tv_sec ) || (0 > (ts)->tv_nsec) ) { \
+ if ( -1000000000 >= (ts)->tv_nsec ) { \
+ (ts)->tv_nsec += 1000000000; \
+ (ts)->tv_sec--; \
+ } else if ( 0 < (ts)->tv_nsec ) { \
+ (ts)->tv_nsec -= 1000000000; \
+ (ts)->tv_sec++; \
+ } \
+ } else { \
+ if ( 1000000000 <= (ts)->tv_nsec ) { \
+ (ts)->tv_nsec -= 1000000000; \
+ (ts)->tv_sec++; \
+ } else if ( 0 > (ts)->tv_nsec ) { \
+ (ts)->tv_nsec += 1000000000; \
+ (ts)->tv_sec--; \
+ } \
} \
} while (0)