Skip to content

Commit

Permalink
Merge branch 'num2str-patch' of https://github.com/gloit042/fio
Browse files Browse the repository at this point in the history
* 'num2str-patch' of https://github.com/gloit042/fio:
  num2str: fix precision loss bug when the fractional part is close to 1
  • Loading branch information
axboe committed Jan 9, 2021
2 parents 8f14dc6 + c736b36 commit 674428a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/num2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units)
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;
Expand Down

0 comments on commit 674428a

Please sign in to comment.