[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: numfmt (=print 'human' sizes) updates

From: Pádraig Brady
Subject: Re: numfmt (=print 'human' sizes) updates
Date: Mon, 04 Feb 2013 03:01:46 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 02/01/2013 10:25 PM, Assaf Gordon wrote:
Hello Pádraig,

Thanks for carrying this through - I think it's becoming a nice little 

Couple of small issues:

     numfmt: Don't process fields in command args by default

Ok I dropped this due to the inconsistency, but made it easier to
process the whole argument with -d '' (like cut).

Last, accepting white-space but not emitting them might affect auto-padding (I 
did not check it thoroughly, though):
     $ ./src/numfmt --from=si --to=iec "45K"
     $ ./src/numfmt --from=si --to=iec "45 K"
     $ ./src/numfmt --from=si --to=iec "45  K"
     $ ./src/numfmt --from=si --to=iec "45   K"

Auto padding is only enabled with isblank() delimiters,
which excludes this case.

     numfmt: support negative numbers

But this also introduces a tiny bug due to my (limited) rounding functions:

     $ ./src/numfmt --from=si -- -9K
     $ ./src/numfmt --from=si -- -9.1K
     $ ./src/numfmt --from=si -- -9.2K

And also:
     $ ./src/numfmt --to=iec -- 90000
     $ ./src/numfmt --to=iec -- -90000

Yes good point. I fixed up the negative handling
and also reworked the rounding functionality a bit.

The new patch set at:
adds these:

    numfmt: add more TODO notes

    numfmt: apply rounding for all numbers

    This is significant when scaling with --to-unit for example.
    Without this we're left with printf's nearest rounding.

    * src/numfmt.c (double_to_human): Apply rounding to all numbers.
    * tests/misc/ Add tests for all rounding combinations.

    numfmt: use more abstract names for the rounding methods

    Also add the "towards-zero" method which is equivalent to trunc().

    numfmt: increase width of rounding functions from int to intmax_t

    numfmt: fix negative number support

    * src/numfmt.c (simple_round_from_zero): A new function equivalent
    to ceil() for positive numbers, but symmetrically rounds away from
    zero for negative numbers.  Set this as the default rounding method.
    (absld): A new function to get the absolute value of a long double,
    without the need for libm.  Use this throughout when comparing
    the magnitude of floating point values.
    * tests/misc/ Add new tests for negative number formats,
    and rounding issues.

    numfmt: handle an empty initial field

    -d: --field=2 ':2:3' should operate on "2"

    * src/numfmt.c (skip_fields): Account for an empty initial field.
    * tests/misc/ Add a test.

    numfmt: allow specifying -d '' to process the whole line

    * src/numfmt.c (main): Allow the NUL delimiter which is easy
    to specify in all shells.
    * tests/misc/ Adjust accordingly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]