From: Harlan Stenn Date: Mon, 17 Apr 2023 09:19:46 +0000 (-0500) Subject: Use correct rounding in mstolfp() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9df359d6d7e8c9b63595f9d908124679ada2e2b4;p=thirdparty%2Fntp.git Use correct rounding in mstolfp() bk: 643d0f321WzNkRDNEL3OHseXdQR9AA --- diff --git a/ChangeLog b/ChangeLog index fc27b2be9..16486f683 100644 --- a/ChangeLog +++ b/ChangeLog @@ -79,6 +79,7 @@ Integrated patch from Brian Utterback. * [Bug 2525] Turn on automake subdir-objects across the project. * [Bug 2410] syslog an error message on panic exceeded. +* Use correct rounding in mstolfp(). perlinger/hart * M_ADDF should use u_int32. * Only define tv_fmt_libbuf() if we will use it. * Use recv_buffer instead of the longer recv_space.X_recv_buffer. hart/stenn diff --git a/libntp/mstolfp.c b/libntp/mstolfp.c index c82b7f590..428f71bdb 100644 --- a/libntp/mstolfp.c +++ b/libntp/mstolfp.c @@ -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; }