[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 13/12] qapi: refine human printing of sizes
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 13/12] qapi: refine human printing of sizes |
Date: |
Thu, 30 Jan 2014 13:16:11 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
On 01/30/2014 09:42 AM, Paolo Bonzini wrote:
> This fixes several bugs or shortcomings of the previous pretty-printer.
> In particular:
>
> * use PRIu64 instead of casting to long long
>
> * the exact value is included too
>
> * the correct unit of measure (MiB, GiB, etc.) is used. PiB and EiB
> are added too.
>
> * due to an off-by-one error, 512*2^30 was printed as 0.500MiB rather than
> 512MiB. floor(log2(val)) is equal to 63 - clz(val), while the code used 64.
>
> * The desired specification is %g rather than %f, which always uses three
> decimals in the current code. However %g would switch to scientific
> notation when the integer part is >= 1000 (e.g. 1000*2^30). To keep the
> code simple, switch to the higher power when the integer part is >= 1000;
> overflow is avoided by using frexp instead of clz.
>
> Suggested-by: Eric Blake <address@hidden>
> Signed-off-by: Paolo Bonzini <address@hidden>
> ---
> qapi/string-output-visitor.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
>
>
> - out = g_strdup_printf("%0.03f%c", (double)val/div, suffixes[i]);
> + out = g_strdup_printf("%"PRIu64" (%0.3g %c%s)", val,
For 1152, the old code would print 1.125k, while the new code prints
only 1.12k. But that's acceptable in my eyes (Remember, %0.3g is how
many significant digits, where both 0.999 and 1.01 have 3 digits).
I also checked that overflow is not possible, and checked several border
cases. Much nicer!
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH 08/12] qdev: use human mode in "info qtree", (continued)
- [Qemu-devel] [PATCH 09/12] qdev: remove most legacy printers, Paolo Bonzini, 2014/01/30
- [Qemu-devel] [PATCH 10/12] qdev: remove hex8/32/64 property types, Paolo Bonzini, 2014/01/30
- [Qemu-devel] [PATCH 11/12] qdev: add enum property types to QAPI schema, Paolo Bonzini, 2014/01/30
- [Qemu-devel] [PATCH 12/12] qdev: use QAPI type names for properties, Paolo Bonzini, 2014/01/30
- [Qemu-devel] [PATCH 13/12] qapi: refine human printing of sizes, Paolo Bonzini, 2014/01/30
- Re: [Qemu-devel] [PATCH 13/12] qapi: refine human printing of sizes,
Eric Blake <=