[Git][NTPsec/ntpsec][master] 2 commits: Add global macros for MICROSECOND, MICROSECONDS, and NANOSECOND
Gary E. Miller
gitlab at mg.gitlab.com
Sat Mar 11 22:54:54 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
7dea3218 by Gary E. Miller at 2017-03-11T14:30:40-08:00
Add global macros for MICROSECOND, MICROSECONDS, and NANOSECOND
>From suggestion by Achim Gratz.
- - - - -
ac4cd73d by Gary E. Miller at 2017-03-11T14:53:58-08:00
Use new *SECOND* macros.
>From a suggestion by Achim Gratz.
- - - - -
3 changed files:
- include/timespecops.h
- libntp/systime.c
- ntptime/ntptime.c
Changes:
=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -49,8 +49,15 @@
#include "timetoa.h"
+/* microseconds per second */
+#define MICROSECONDS 1000000
+/* sconds per microsecond */
+#define MICROSECOND 1.0e-6
+
/* nanoseconds per second */
#define NANOSECONDS 1000000000
+/* seconds per nanosecond */
+#define NANOSECOND 1.0e-9
/* predicate: returns true if the nanoseconds are in nominal range */
#define timespec_isnormal(x) \
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -84,7 +84,7 @@ set_sys_fuzz(
sys_fuzz = fuzz_val;
//INSIST(sys_fuzz >= 0);
//INSIST(sys_fuzz <= 1.0);
- sys_fuzz_nsec = (long)(sys_fuzz * 1e9 + 0.5);
+ sys_fuzz_nsec = (long)(sys_fuzz * NANOSECONDS + 0.5);
}
@@ -106,8 +106,8 @@ get_ostime(
}
if (trunc_os_clock) {
- ticks = (long)((tsp->tv_nsec * 1e-9) / sys_tick);
- tsp->tv_nsec = (long)(ticks * 1e9 * sys_tick);
+ ticks = (long)((tsp->tv_nsec * NANOSECOND) / sys_tick);
+ tsp->tv_nsec = (long)(ticks * NANOSECONDS * sys_tick);
}
}
@@ -160,7 +160,7 @@ normalize_time(
msyslog(LOG_ERR,
"get_systime Lamport advance exceeds one second (%.9f)",
ts_lam.tv_sec +
- 1e-9 * ts_lam.tv_nsec);
+ NANOSECOND * ts_lam.tv_nsec);
exit(1);
}
if (!lamport_violated)
@@ -271,20 +271,20 @@ adj_systime(
if (sys_tick > sys_fuzz)
quant = sys_tick;
else
- quant = 1e-6;
+ quant = MICROSECOND;
ticks = (long)(dtemp / quant + .5);
- adjtv.tv_usec = (long)(ticks * quant * 1.e6 + .5);
+ adjtv.tv_usec = (long)(ticks * quant * MICROSECONDS + .5);
/* The rounding in the conversions could push us over the
* limits: make sure the result is properly normalised!
* note: sign comes later, all numbers non-negative here.
*/
- if (adjtv.tv_usec >= 1000000) {
+ if (adjtv.tv_usec >= MICROSECONDS) {
adjtv.tv_sec += 1;
- adjtv.tv_usec -= 1000000;
+ adjtv.tv_usec -= MICROSECONDS;
dtemp -= 1.;
}
/* set the new residual with leftover from correction */
- sys_residual = dtemp - adjtv.tv_usec * 1.e-6;
+ sys_residual = dtemp - adjtv.tv_usec * MICROSECOND;
/*
* Convert to signed seconds and microseconds for the Unix
=====================================
ntptime/ntptime.c
=====================================
--- a/ntptime/ntptime.c
+++ b/ntptime/ntptime.c
@@ -26,9 +26,6 @@
#define tv_frac_sec tv_usec
#endif
-/* microseconds per second */
-#define MICROSECONDS 1000000
-
/*
* Convert usec to a time stamp fraction.
*/
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c027ee95170456579840e85d795a1be79a4ec9d5...ac4cd73d128e53484d06d8d4fe63cc8c14e5de82
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170311/c8059dd5/attachment.html>
More information about the vc
mailing list