mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 17:35:06 -05:00
util: fix rounding of negative numbers in UTI_DoubleToTimeval()
This commit is contained in:
committed by
Miroslav Lichvar
parent
7f58852ec0
commit
0fc0f906e1
8
util.c
8
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user