diff --git a/ntp_core.c b/ntp_core.c index 240723c..b61aba5 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -2604,7 +2604,7 @@ broadcast_timeout(void *arg) int poll; destination = ARR_GetElement(broadcasts, (long)arg); - poll = log(destination->interval) / log(2.0) + 0.5; + poll = round(log(destination->interval) / log(2.0)); UTI_ZeroNtp64(&orig_ts); zero_local_timestamp(&recv_ts); diff --git a/refclock.c b/refclock.c index 23a495a..968caa7 100644 --- a/refclock.c +++ b/refclock.c @@ -572,10 +572,7 @@ RCL_AddCookedPulse(RCL_Instance instance, struct timespec *cooked_time, } /* Align the offset to the reference sample */ - if ((ref_sample.offset - offset) >= 0.0) - shift = (long)((ref_sample.offset - offset) * rate + 0.5) / (double)rate; - else - shift = (long)((ref_sample.offset - offset) * rate - 0.5) / (double)rate; + shift = round((ref_sample.offset - offset) * rate) / rate; offset += shift; diff --git a/sys_linux.c b/sys_linux.c index 2b53f72..8fba259 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -97,21 +97,6 @@ static int have_setoffset; updated in the kernel */ static int tick_update_hz; -/* ================================================== */ - -inline static long -our_round(double x) -{ - long y; - - if (x > 0.0) - y = x + 0.5; - else - y = x - 0.5; - - return y; -} - /* ================================================== */ /* Positive means currently fast of true time, i.e. jump backwards */ @@ -149,7 +134,7 @@ set_frequency(double freq_ppm) double required_freq; int required_delta_tick; - required_delta_tick = our_round(freq_ppm / dhz); + required_delta_tick = round(freq_ppm / dhz); /* Older kernels (pre-2.6.18) don't apply the frequency offset exactly as set by adjtimex() and a scaling constant (that depends on the internal diff --git a/util.c b/util.c index 2ae5deb..a853e16 100644 --- a/util.c +++ b/util.c @@ -123,7 +123,7 @@ UTI_DoubleToTimeval(double a, struct timeval *b) b->tv_sec = a; frac_part = 1.0e6 * (a - b->tv_sec); - b->tv_usec = frac_part > 0 ? frac_part + 0.5 : frac_part - 0.5; + b->tv_usec = round(frac_part); UTI_NormaliseTimeval(b); }