FreeBSD/contrib/ntp/libntp/ntp_calendar.c
/* Some of the calculations need to multiply the input by 4 before doing
 * a division. This can cause overflow and strange results. Therefore we
 * clamp / saturate the input operand. And since we do the calculations
 * in unsigned int with an extra sign flag/mask, we only loose one bit
 * of the input value range.
 */
Some of the calculations need to multiply the input by 4 before doing
a division. This can cause overflow and strange results. Therefore we
clamp / saturate the input operand. And since we do the calculations
in unsigned int with an extra sign flag/mask, we only loose one bit
of the input value range.
Some of the calculations need to multiply the input by 4 before doing a division . This can cause overflow and strange results . Therefore we clamp / saturate the input operand . And since we do the calculations in unsigned int with an extra sign flag / mask we only loose one bit of the input value range .
static inline uint32_t
uint32_saturate(
	uint32_t vu,
	uint32_t mu)
{
	static const uint32_t limit = UINT32_MAX/4u;
	if ((mu ^ vu) > limit) {
		vu    = mu ^ limit;
		errno = EDOM;
	}
	return vu;
}
static inline uint32_t uint32_saturate ( uint32_t vu , uint32_t mu ) { static const uint32_t limit = UINT32_MAX / 4u ; if ( ( mu ^ vu ) > limit ) { vu = mu ^ limit ; errno = EDOM ; } return vu ; }
Some of the calculations need to multiply the input by 4 before doing
 a division.
Some of the calculations need to multiply the input by 4 before doing a division .