]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/strutils: parse_size() fix frac digit calculation
authorKarel Zak <kzak@redhat.com>
Mon, 13 May 2019 15:07:14 +0000 (17:07 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 13 May 2019 15:07:14 +0000 (17:07 +0200)
commit8c368dc6d3771d4655c953c42ff009f20d51de1f
treeff4c8bf0697c12ac198e1c61d7b7674d4da1bb75
parent482e0a07544501ece40314d045b4c70ba9546295
lib/strutils: parse_size() fix frac digit calculation

Old code:

./test_strutils --size 0.5MiB
0.5MiB :               512000 :     500K :      500 KiB
./test_strutils --size 0.50MiB
0.50MiB :              5120000 :     4.9M :      4.9 MiB

New code:
./test_strutils --size 0.5MiB
0.5MiB :               524288 :     512K :      512 KiB
./test_strutils --size 0.50MiB
       0.50MiB :               524288 :     512K :      512 KiB

Note that the new implementation also does not use float points,
because we need to support PiB and so on... it seems good enough for
things like:

        ./test_strutils --size 7.13G
                7.13G :           7656104581 :     7.1G :      7.1 GiB
        ./test_strutils --size 7.16G
                7.16G :           7690675814 :     7.2G :      7.2 GiB

to avoid situation where cfdisk creates partition with completely
crazy numbers.

Addresses: https://github.com/karelzak/util-linux/issues/782
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/strutils.c