"f + 0.5" does not round correctly for values very close to
".5" for every integer multiple, e.g. "0.499999975".
Found by clang-tidy's "bugprone-incorrect-roundings" check.
Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/util/virhostuptime.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/util/virhostuptime.c b/src/util/virhostuptime.c
index 696a38fbb5..7508a5a9b6 100644
--- a/src/util/virhostuptime.c
+++ b/src/util/virhostuptime.c
@@ -32,6 +32,8 @@
#include "virtime.h"
#include "virthread.h"
+#include <math.h>
+
#define VIR_FROM_THIS VIR_FROM_NONE
VIR_LOG_INIT("util.virhostuptime");
@@ -76,7 +78,7 @@ virHostGetBootTimeProcfs(unsigned long long *btime)
return -EINVAL;
}
- *btime = now / 1000 - up + 0.5;
+ *btime = llround(now / 1000 - up);
return 0;
}
--
2.26.2