summaryrefslogtreecommitdiff
path: root/gpsd.h-tail
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2015-02-11 19:26:03 -0800
committerGary E. Miller <gem@rellim.com>2015-02-11 19:26:03 -0800
commit927ce93c49f8a9e84433141357e3602ada077850 (patch)
treef58b86a49fa5d565538d6806c56aea67a046ec08 /gpsd.h-tail
parentc988130851015de651b2632a1f4068c7c3661c1e (diff)
downloadgpsd-927ce93c49f8a9e84433141357e3602ada077850.tar.gz
Add some comments to TS_NORM()
Diffstat (limited to 'gpsd.h-tail')
-rw-r--r--gpsd.h-tail15
1 files changed, 13 insertions, 2 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail
index 6436f0bc..85895c5c 100644
--- a/gpsd.h-tail
+++ b/gpsd.h-tail
@@ -883,7 +883,16 @@ extern void ntpshm_link_activate(struct gps_device_t *);
extern void pps_early_init(struct gps_context_t *);
#endif /* PPS_ENABLE */
-/* normalize a timespec */
+/* normalize a timespec
+ *
+ * three cases to note
+ * if tv_sec is positve, then tv_nsec must be positive
+ * if tv_sec is negative, then tv_nsec must be negative
+ * if tv_sec is zero, then tv_nsec may be positive or negative.
+ *
+ * this only handles the case where two normalized timespecs
+ * are added or subracted. (e.g. only a one needs to be borrowed/carried
+ */
static inline void TS_NORM( struct timespec *ts)
{
if ( ( 1 <= ts->tv_sec ) ||
@@ -894,16 +903,18 @@ static inline void TS_NORM( struct timespec *ts)
ts->tv_nsec -= 1000000000;
ts->tv_sec++;
} else if ( 0 > (ts)->tv_nsec ) {
- /* carry from tv_sec */
+ /* carry to tv_sec */
ts->tv_nsec += 1000000000;
ts->tv_sec--;
}
} else {
/* result is negative */
if ( -1000000000 >= ts->tv_nsec ) {
+ /* carry to tv_sec */
ts->tv_nsec += 1000000000;
ts->tv_sec--;
} else if ( 0 < ts->tv_nsec ) {
+ /* borrow from tv_sec */
ts->tv_nsec -= 1000000000;
ts->tv_sec++;
}