GNU bug report logs -
#47103
numfmt: invalid suffix 'k'
Previous Next
Full log
Message #11 received at 47103 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 25/11/2023 21:27, Sven Köhler wrote:
> Not only --from=si is broken. Also --to=si is broken:
>
> $ numfmt --to=si 3000
> 3,0K
>
> In order to not break backwards compatibility, you probably have to
> introduce a switch --lowercase-kilo such that --to=si produces proper SI
> compliant output. Then have --from=si accept both uppercase and lowercase k.
>
> I have to say, that uppercause K is quite common, but it is not correct
> as far as SI prefixes are concerned.
>
> Also note that Ki in iec-i mode is quite correct. I'm torn about iec
> mode. I believe that people silently switch 1000 for 1024 and use the
> lower case k as well as uppercase K. Maybe numfmt should have an option
> to accept/produce both here as well?
>
> Is there really a standard/specification that allows k/K for 1024?
> Wikipedia only lists Ki as IEC prefixes.
I was thinking we only supported uppercase K for compat with output from existing coreutils.
But in fact it's quite the opposite. Other coreutils output lowercase k
when operating in SI mode. For e.g. this gives an error:
$ ls -lh --si /bin/ | numfmt --from=si --field=5
numfmt: invalid suffix in input: ‘54k’
So we should at least accept lowercase k.
As for outputting lowercase k for the SI case, the coreutils texinfo has the following
in relation to these Kilo prefixes:
‘kB’
kilobyte: 10^3 = 1000.
‘k’
‘K’
‘KiB’
kibibyte: 2^{10} = 1024. ‘K’ is special: the SI prefix is ‘k’ and
the ISO/IEC 80000-13 prefix is ‘Ki’, but tradition and POSIX use
‘k’ to mean ‘KiB’.
So one might be conservative here and keep outputting uppercase K in SI mode.
However the above is really in relation to specifying block sizes, to df or dd etc.,
so we should probably output lower case k for consistency with other coreutils at least.
We could be conservative here and have a new --to=Si option (note the casing)
to explicitly select/allow variable cased SI prefixes, but I'm not sure that's needed.
For IEC mode, we should could just allow uppercase K,
but it's simpler and more flexible to accept lowercase k here, without much ambiguity.
As for not allowing uppercase K in SI mode, that's probably overkill,
and would cause more problems than it would solve. One edge case
it would solve is when working with a Kelvin suffix, to avoid
the ambiguity in the first case of the following.
That's too much of an edge case to worry about I think:
$ numfmt --suffix=K --from=si 500K
500K
$ numfmt --suffix=K --from=si 500M
500000000K
$ numfmt --suffix=K --from=si 500KK
500000K
The attached make the adjustment to allow 'k' always,
and output 'k' in SI mode. Tests will need adjusting,
but no need to clutter the discussion patch with that.
cheers,
Pádraig.
[numfmt-k.patch (text/x-patch, attachment)]
This bug report was last modified 1 year and 179 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.