-/* $OpenBSD: ntp.h,v 1.14 2020/01/30 15:55:41 otto Exp $ */
+/* $OpenBSD: ntp.h,v 1.15 2023/11/15 15:52:09 otto Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
u_int32_t int_partl;
u_int32_t fractionl;
};
+#define L_DENOMINATOR (UINT32_MAX + 1ULL)
struct s_fixedpt {
u_int16_t int_parts;
u_int16_t fractions;
};
+#define S_DENOMINATOR (UINT16_MAX + 1)
/* RFC Section 4
*
-/* $OpenBSD: util.c,v 1.25 2020/01/30 15:55:41 otto Exp $ */
+/* $OpenBSD: util.c,v 1.26 2023/11/15 15:52:09 otto Exp $ */
/*
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
if (lfp.int_partl <= INT32_MAX)
base++;
ret = base * SECS_IN_ERA;
- ret += (double)(lfp.int_partl) + ((double)lfp.fractionl / UINT_MAX);
+ ret += (double)(lfp.int_partl) + ((double)lfp.fractionl / L_DENOMINATOR);
return (ret);
}
while (d > SECS_IN_ERA)
d -= SECS_IN_ERA;
lfp.int_partl = htonl((u_int32_t)d);
- lfp.fractionl = htonl((u_int32_t)((d - (u_int32_t)d) * UINT_MAX));
+ lfp.fractionl = htonl((u_int32_t)((d - (u_int32_t)d) * L_DENOMINATOR));
return (lfp);
}
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 / S_DENOMINATOR);
return (ret);
}
struct s_fixedpt sfp;
sfp.int_parts = htons((u_int16_t)d);
- sfp.fractions = htons((u_int16_t)((d - (u_int16_t)d) * USHRT_MAX));
+ sfp.fractions = htons((u_int16_t)((d - (u_int16_t)d) * S_DENOMINATOR));
return (sfp);
}