mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 17:25:07 -05:00
use round() for rounding
Replace casting of values incremented by +0.5/-0.5 with round().
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
17
sys_linux.c
17
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
|
||||
|
||||
Reference in New Issue
Block a user