Re: [chrony-dev] [PATCH] UTI_DoubleToTimeval() - fix rounding of negative numbers |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
On Thu, Jul 23, 2015 at 11:59:31PM +1200, Bryan Christianson wrote:
Applied, thanks.
> ---
> util.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/util.c b/util.c
> index 0add5df..8483626 100644
> --- a/util.c
> +++ b/util.c
> @@ -46,11 +46,13 @@ UTI_TimevalToDouble(struct timeval *a, double *b)
> INLINE_STATIC void
> UTI_DoubleToTimeval(double a, struct timeval *b)
> {
> - long int_part, frac_part;
> + long int_part;
> + double frac_part;
> int_part = (long)(a);
> - frac_part = (long)(0.5 + 1.0e6 * (a - (double)(int_part)));
> + frac_part = 1.0e6 * (a - (double)(int_part));
> + frac_part = frac_part > 0 ? frac_part + 0.5 : frac_part - 0.5;
> b->tv_sec = int_part;
> - b->tv_usec = frac_part;
> + b->tv_usec = (long)frac_part;
> UTI_NormaliseTimeval(b);
> }
--
Miroslav Lichvar
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.