diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-04-01 05:52:25 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-04-01 05:52:25 -0400 |
commit | b84b15bb0c315a9d26cd1658c2e21bddacb83ae2 (patch) | |
tree | 02e94d77cabc00175a7edd429fb9f32792054ea2 /timespec.h | |
parent | e498ed8029b4488eb09436df0716bc12a076c161 (diff) | |
download | gpsd-b84b15bb0c315a9d26cd1658c2e21bddacb83ae2.tar.gz |
Formulas are easier to read without more zeros than eyes can process.
Diffstat (limited to 'timespec.h')
-rw-r--r-- | timespec.h | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -16,29 +16,32 @@ * this only handles the case where two normalized timespecs * are added or subracted. (e.g. only a one needs to be borrowed/carried */ +#define NS_IN_SEC 1000000000 +#define MS_IN_SEC 1000000 + static inline void TS_NORM( struct timespec *ts) { if ( ( 1 <= ts->tv_sec ) || ( (0 == ts->tv_sec ) && (0 <= ts->tv_nsec ) ) ) { /* result is positive */ - if ( 1000000000 <= ts->tv_nsec ) { + if ( NS_IN_SEC <= ts->tv_nsec ) { /* borrow from tv_sec */ - ts->tv_nsec -= 1000000000; + ts->tv_nsec -= NS_IN_SEC; ts->tv_sec++; } else if ( 0 > (ts)->tv_nsec ) { /* carry to tv_sec */ - ts->tv_nsec += 1000000000; + ts->tv_nsec += NS_IN_SEC; ts->tv_sec--; } } else { /* result is negative */ - if ( -1000000000 >= ts->tv_nsec ) { + if ( -NS_IN_SEC >= ts->tv_nsec ) { /* carry to tv_sec */ - ts->tv_nsec += 1000000000; + ts->tv_nsec += NS_IN_SEC; ts->tv_sec--; } else if ( 0 < ts->tv_nsec ) { /* borrow from tv_sec */ - ts->tv_nsec -= 1000000000; + ts->tv_nsec -= NS_IN_SEC; ts->tv_sec++; } } @@ -47,11 +50,11 @@ static inline void TS_NORM( struct timespec *ts) /* normalize a timeval */ #define TV_NORM(tv) \ do { \ - if ( 1000000 <= (tv)->tv_usec ) { \ - (tv)->tv_usec -= 1000000; \ + if ( MS_IN_SEC <= (tv)->tv_usec ) { \ + (tv)->tv_usec -= MS_IN_SEC; \ (tv)->tv_sec++; \ } else if ( 0 > (tv)->tv_usec ) { \ - (tv)->tv_usec += 1000000; \ + (tv)->tv_usec += MS_IN_SEC; \ (tv)->tv_sec--; \ } \ } while (0) |