]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Use correct rounding in mstolfp()
authorHarlan Stenn <stenn@ntp.org>
Mon, 17 Apr 2023 09:19:46 +0000 (04:19 -0500)
committerHarlan Stenn <stenn@ntp.org>
Mon, 17 Apr 2023 09:19:46 +0000 (04:19 -0500)
bk: 643d0f321WzNkRDNEL3OHseXdQR9AA

ChangeLog
libntp/mstolfp.c

index fc27b2be96403b56c3fd22e61832737259887245..16486f683bf8b03e0e3f038df4e84a814cf7fed8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -79,6 +79,7 @@
              Integrated patch from Brian Utterback. <hart@ntp.org>
 * [Bug 2525] Turn on automake subdir-objects across the project. <hart@ntp.org>
 * [Bug 2410] syslog an error message on panic exceeded. <brian.utterback@oracle.com>
+* Use correct rounding in mstolfp(). perlinger/hart
 * M_ADDF should use u_int32.  <hart@ntp.org>
 * Only define tv_fmt_libbuf() if we will use it. <stenn@ntp.org>
 * Use recv_buffer instead of the longer recv_space.X_recv_buffer. hart/stenn
index c82b7f5909bfb5899bb640f9343fe6d05b70c502..428f71bdbae966c095349cbdf73968dd3b00d621 100644 (file)
@@ -61,17 +61,11 @@ mstolfp(
        lfp->l_uf |= q;
        r -= q * 1000u;
 
-       /* numerically, rounding should happen *after* the sign correction
-        * but that would produce different bit patterns from the previous
-        * implementation. (off-by-one in the fraction. Neglectible, but
-        * messy to fix in the unit tests. So we stay with the slightly
-        * suboptimal calculation...)
-        */
-       /* round */
-       if (r >= 500)
-               L_ADDUF(lfp, 1u);
        /* fix sign */
        if (neg)
                L_NEG(lfp);
+       /* round */
+       if (r >= 500)
+               L_ADDF(lfp, (neg ? -1 : 1));
        return 1;
 }