[chrony-dev] [PATCH] UTI_DoubleToTimeval() - fix rounding of negative numbers |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH] UTI_DoubleToTimeval() - fix rounding of negative numbers
- From: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Date: Thu, 23 Jul 2015 23:59:31 +1200
- Cc: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=a0-2; h=Feedback-ID:X-Smtpcorp-Track:Message-Id:Date: Subject:To:From; bh=CPkOs49y7Fo+JOG50mZF00yJBUkMe19df2mLmQ8JIYA=; b=mWeZ1jrYp F6i+4yvqOmD+BJ3zobBFXGl7lgGRDhDs7sUbaM5kIQYxs6vPbAcBQiXDMHCxU82md/UUK6wjyogiH VIxM5ufuHzy26tCTyW3ockrCP30zI3yn1wzIVo32UxYY0tEhOWs9le3h+p6CO/5/PYIViLAAV+yUI j+Gov2N/FneHYa1fIsxc3p9zG+OZItTo3OxZyOYEwqV9N9RPK+Z93wY4uzg6ELIFi4SL7//iUPgE4 OEd1X3KA3p0WvoLE/tEU50w0eack71QGZ+ESkSQatS0neYZYyqljdQtTFcfnlvVzzVfxDmi463wjU xSR/zQbfYnPyhrSZkiehbCbUw==;
- Feedback-id: 149811m:149811acx33YQ:149811sTstL4m4fR:SMTPCORP
---
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);
}
--
2.3.2 (Apple Git-55)
--
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.