[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox-cvs
Subject: [git commit] ntpd: correct fixed->float conversions of fractions
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2023-01-17 16:01:05
Message-ID: 20230117160249.A5F9087634 () busybox ! osuosl ! org
[Download RAW message or body]
commit: https://git.busybox.net/busybox/commit/?id=c344ca6c7f5d8468624ae518d2912d1d9612cb91
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
Need to divide by (1<<32), not by (1<<32)-1.
Fraction of 0xffffffff is not 1 whole second.
function old new delta
.rodata 105264 105268 +4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
networking/ntpd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 4365166ff..ff49550e9 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -564,7 +564,7 @@ lfp_to_d(l_fixedpt_t lfp)
double ret;
lfp.int_partl = ntohl(lfp.int_partl);
lfp.fractionl = ntohl(lfp.fractionl);
- ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX);
+ ret = (double)lfp.int_partl + ((double)lfp.fractionl / (1ULL << 32));
/*
* Shift timestamps before 1970 to the second NTP era (2036-2106):
* int_partl value of OFFSET_1900_1970 (2208988800) is interpreted as
@@ -581,7 +581,7 @@ sfp_to_d(s_fixedpt_t sfp)
double ret;
sfp.int_parts = ntohs(sfp.int_parts);
sfp.fractions = ntohs(sfp.fractions);
- ret = (double)sfp.int_parts + ((double)sfp.fractions / USHRT_MAX);
+ ret = (double)sfp.int_parts + ((double)sfp.fractions / (1 << 16));
return ret;
}
#if ENABLE_FEATURE_NTPD_SERVER
@@ -591,7 +591,7 @@ d_to_lfp(l_fixedpt_t *lfp, double d)
uint32_t intl;
uint32_t frac;
intl = (uint32_t)(time_t)d;
- frac = (uint32_t)((d - (time_t)d) * UINT_MAX);
+ frac = (uint32_t)((d - (time_t)d) * 0xffffffff);
lfp->int_partl = htonl(intl);
lfp->fractionl = htonl(frac);
}
@@ -601,7 +601,7 @@ d_to_sfp(s_fixedpt_t *sfp, double d)
uint16_t ints;
uint16_t frac;
ints = (uint16_t)d;
- frac = (uint16_t)((d - ints) * USHRT_MAX);
+ frac = (uint16_t)((d - ints) * 0xffff);
sfp->int_parts = htons(ints);
sfp->fractions = htons(frac);
}
_______________________________________________
busybox-cvs mailing list
busybox-cvs@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic