summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgloit042 <gloit042@gmail.com>2020-12-21 00:35:21 +0800
committergloit042 <gloit042@gmail.com>2020-12-21 10:14:38 +0800
commitc736b361190e1133b4d407a6c7615bf8c4d9c262 (patch)
tree8151001e70d019d60d0405aa4b8b6a3851b4be52 /lib
parentced224611b039df68ceebde4733269f4f6606912 (diff)
downloadfio-c736b361190e1133b4d407a6c7615bf8c4d9c262.tar.gz
fio-c736b361190e1133b4d407a6c7615bf8c4d9c262.tar.bz2
num2str: fix precision loss bug when the fractional part is close to 1
example: The result of num2str(11999999999999, 4, 1, 0, N2S_NONE) should be "12.0G", but current result is "11.0G". Signed-off-by: Jiahao Li <gloit042@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/num2str.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/num2str.c b/lib/num2str.c
index 726f1c44..423d97b2 100644
--- a/lib/num2str.c
+++ b/lib/num2str.c
@@ -112,6 +112,9 @@ done:
sprintf(tmp, "%.*f", (int)(maxlen - strlen(tmp) - 1),
(double)modulo / (double)thousand);
+ if (tmp[0] == '1')
+ num++;
+
if (asprintf(&buf, "%llu.%s%s%s", (unsigned long long) num, &tmp[2],
unitprefix[post_index], unitstr[units]) < 0)
buf = NULL;