From: Christian Hesse <mail@eworm.de>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Stephen Hemminger <stephen@networkplumber.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH v2 1/1] ip-link: in human readable output use dynamic precision length
Date: Tue, 4 Nov 2014 22:10:38 +0100 [thread overview]
Message-ID: <20141104221038.440fd9d7@leda.localdomain> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1C9E72A7@AcuExch.aculab.com>
[-- Attachment #1: Type: text/plain, Size: 1484 bytes --]
David Laight <David.Laight@ACULAB.COM> on Tue, 2014/11/04 11:06:
> From: Christian Hesse
> ...
> > ...
> > @@ -343,8 +344,11 @@ static void print_num(FILE *fp, unsigned width,
> > uint64_t count) ++prefix;
> > }
> >
> > - snprintf(buf, sizeof(buf), "%.1f%c%s", (double) count / powi,
> > - *prefix, use_iec ? "i" : "");
> > + if ((precision = 3 - snprintf(NULL, 0, "%"PRIu64, count / powi))
> > < 0)
>
> Don't put assignments in conditionals.
Ok. :D
I do not like this at all... snprintf() would be nice for a catch-all, but we
have to take care of negative values. So let's try something different.
I will think about it and send a new patch.
> > + precision = 0;
> > +
> > + snprintf(buf, sizeof(buf), "%.*f%c%s", precision,
> > + (double) count / powi, *prefix, use_iec ? "i" : "");
> >
> > fprintf(fp, "%-*s ", width, buf);
> > }
>
> The above will go wrong in all sorts of horrid ways....
> For instance you are doing a truncating integer divide, but the FP
> value will get rounded for display.
>
> It would be safer to use integers throughout.
My implementation used integers, but Stephen changes this to floating point
with his cleanups.
IMHO the rounding is ok. This is for *human* readability. ;)
Whoever wants correct values should not ask ip to print human readable values
but rely on pure numbers.
> Oh, and a 2Mbit E1 link is actually 2048000 :-)
Sorry? Did not get the point.
--
Best regards,
Chris
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2014-11-04 21:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-04 9:39 [PATCH 1/1] ip-link: in human readable output use dynamic precision length Christian Hesse
2014-11-04 10:44 ` Christian Hesse
2014-11-04 10:50 ` [PATCH v2 " Christian Hesse
2014-11-04 11:06 ` David Laight
2014-11-04 21:10 ` Christian Hesse [this message]
2014-11-04 21:17 ` [PATCH v3 " Christian Hesse
2014-11-05 9:30 ` [PATCH v2 " David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141104221038.440fd9d7@leda.localdomain \
--to=mail@eworm.de \
--cc=David.Laight@ACULAB.COM \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox