]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
use round() for rounding
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 23 Sep 2021 08:01:50 +0000 (10:01 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 23 Sep 2021 13:51:35 +0000 (15:51 +0200)
Replace casting of values incremented by +0.5/-0.5 with round().

ntp_core.c
refclock.c
sys_linux.c
util.c

index 240723cf8fe0fdb3c5959736adffe5b611ced934..b61aba57e80a52069fd02430197703b379670b4b 100644 (file)
@@ -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);
index 23a495a1986f6897a84fef190dcce1f4ea89b03d..968caa74b04f7f7a5d892d91090e705bf4245d8e 100644 (file)
@@ -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;
 
index 2b53f722bd64869b9baf18b4e84299e9826303a3..8fba259e7e5b345b78eaf833d27c852498787734 100644 (file)
@@ -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 2ae5deb3f6182296a72fb7dc9d6be4ff79e97971..a853e1659efba5a5a8255a396d8551e40d46400d 100644 (file)
--- 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);
 }