From: Miroslav Lichvar Date: Thu, 6 Jun 2013 14:30:37 +0000 (+0200) Subject: Fix rounding in UTI_AddDoubleToTimeval with negative increments X-Git-Tag: 1.28-pre1~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62027f1b47ada22a910d02d7eb953d2e6a45bf84;p=thirdparty%2Fchrony.git Fix rounding in UTI_AddDoubleToTimeval with negative increments --- diff --git a/util.c b/util.c index 3ae06d80..aedabebf 100644 --- a/util.c +++ b/util.c @@ -135,7 +135,8 @@ UTI_AddDoubleToTimeval(struct timeval *start, is too marginal here. */ int_part = (long) increment; - frac_part = (long) (0.5 + 1.0e6 * (increment - (double)int_part)); + increment = (increment - int_part) * 1.0e6; + frac_part = (long) (increment > 0.0 ? increment + 0.5 : increment - 0.5); end->tv_sec = int_part + start->tv_sec; end->tv_usec = frac_part + start->tv_usec;