[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1C9E9068@AcuExch.aculab.com>
Date: Wed, 5 Nov 2014 09:30:02 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Christian Hesse' <mail@...rm.de>
CC: Stephen Hemminger <stephen@...workplumber.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: [PATCH v2 1/1] ip-link: in human readable output use dynamic
precision length
From: Christian Hesse
...
>
> 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.
Rounding the value is fine, the difference between 1000 and 1024
is not that great either.
The problem is that the two calculations get rounded differently.
If the FP value ends up being 9.999999 it will be printed as 10.0
but your field width calculation will only have allowed for
a single digit.
> > Oh, and a 2Mbit E1 link is actually 2048000 :-)
>
> Sorry? Did not get the point.
That was really in reference to a much earlier comment about comms
always using 1000.
David
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists