util: add functions for converting new root delay/dispersion

This commit is contained in:
Miroslav Lichvar
2021-11-15 10:25:35 +01:00
parent a652ce7d0e
commit 2e126ed2b5
3 changed files with 43 additions and 0 deletions

31
util.c
View File

@@ -637,6 +637,37 @@ UTI_DoubleToNtp32(double x)
/* ================================================== */
double
UTI_Ntp32f28ToDouble(NTP_int32 x)
{
return ntohl(x) / (double)(1U << 28);
}
/* ================================================== */
NTP_int32
UTI_DoubleToNtp32f28(double x)
{
NTP_int32 r;
if (x >= 4294967295.0 / (1U << 28)) {
r = 0xffffffff;
} else if (x <= 0.0) {
r = 0;
} else {
x *= 1U << 28;
r = x;
/* Round up */
if (r < x)
r++;
}
return htonl(r);
}
/* ================================================== */
void
UTI_ZeroNtp64(NTP_int64 *ts)
{