Re: [chrony-dev] [PATCH] Fix rounding in UTI_DoubleToTimeval() |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
The change looks good, just some comments on the patch and coding style.
On Thu, Jul 23, 2015 at 10:47:27PM +1200, Bryan Christianson wrote:
> From 2e37782a50a493c39435e221b7eef9c107bd2e86 Mon Sep 17 00:00:00 2001
> From: Bryan Christianson <bryan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Is this a valid email address? You might want to set it in git with
this command
$ git config --global user.email xxxxx
Also, does the git send-email command work for you? It would make it
easier for us to review the patches if it wasn't an attachment.
> UTI_DoubleToTimeval(double a, struct timeval *b)
> {
> long int_part, frac_part;
> + double frac;
How about changing the frac_part type to double instead of adding a
new variable and assign it to b->tv_usec directly?
> int_part = (long)(a);
> - frac_part = (long)(0.5 + 1.0e6 * (a - (double)(int_part)));
> + frac = 1.0e6 * (a - (double)int_part);
> + if(frac > 0) {
Between if and ( should be a space. The code loosely follows the Linux kernel
coding style
https://www.kernel.org/doc/Documentation/CodingStyle
> + frac += 0.5;
> + } else {
> + frac -= 0.5;
> + }
If it was written with the ? : operator, it would be four lines
shorter :).
> + frac_part = (long)frac;
> b->tv_sec = int_part;
> b->tv_usec = frac_part;
> UTI_NormaliseTimeval(b);
Thanks,
--
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.