Summary
numfmt --to=<scale> --to-unit=N VALUE selects the output prefix (K, Ki, M, ...) based on the unscaled input VALUE, instead of the final scaled value VALUE / N. GNU selects the prefix based on the scaled result.
Found by fuzz_numfmt.
Reproduction
$ LC_ALL=C /usr/bin/numfmt --to=iec-i --to-unit=885 100000
113
$ target/debug/numfmt --to=iec-i --to-unit=885 100000
0.1Ki
100000 / 885 = 113, which is below 1 Ki (1024), so no suffix should be applied. uutils apparently looks at 100000, picks Ki, and emits 0.1Ki.
Another example:
$ LC_ALL=C /usr/bin/numfmt --to=iec-i --to-unit=885 1000000
1.2Ki
$ target/debug/numfmt --to=iec-i --to-unit=885 1000000
1.1Ki
Scaled value: 1000000 / 885 ≈ 1130, i.e. 1.2Ki (rounding up). uutils seems to compute the suffix from the unscaled value, giving 1.1Ki.
Summary
numfmt --to=<scale> --to-unit=N VALUEselects the output prefix (K,Ki,M, ...) based on the unscaled inputVALUE, instead of the final scaled valueVALUE / N. GNU selects the prefix based on the scaled result.Found by
fuzz_numfmt.Reproduction
100000 / 885 = 113, which is below1 Ki (1024), so no suffix should be applied. uutils apparently looks at100000, picksKi, and emits0.1Ki.Another example:
Scaled value:
1000000 / 885 ≈ 1130, i.e.1.2Ki(rounding up). uutils seems to compute the suffix from the unscaled value, giving1.1Ki.