From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8y27-0003qY-Rq for qemu-devel@nongnu.org; Thu, 30 Jan 2014 15:16:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W8y22-0001oH-1z for qemu-devel@nongnu.org; Thu, 30 Jan 2014 15:16:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35447) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8y21-0001nm-PV for qemu-devel@nongnu.org; Thu, 30 Jan 2014 15:16:13 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0UKGCuH011211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 30 Jan 2014 15:16:12 -0500 Message-ID: <52EAB30B.5010308@redhat.com> Date: Thu, 30 Jan 2014 13:16:11 -0700 From: Eric Blake MIME-Version: 1.0 References: <1391087394-17914-1-git-send-email-pbonzini@redhat.com> <1391100145-25369-1-git-send-email-pbonzini@redhat.com> In-Reply-To: <1391100145-25369-1-git-send-email-pbonzini@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vd8URthvRppcxXNPJeSPAsew6EFVTb78L" Subject: Re: [Qemu-devel] [PATCH 13/12] qapi: refine human printing of sizes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --vd8URthvRppcxXNPJeSPAsew6EFVTb78L Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/30/2014 09:42 AM, Paolo Bonzini wrote: > This fixes several bugs or shortcomings of the previous pretty-printer.= > In particular: >=20 > * use PRIu64 instead of casting to long long >=20 > * the exact value is included too >=20 > * the correct unit of measure (MiB, GiB, etc.) is used. PiB and EiB > are added too. >=20 > * due to an off-by-one error, 512*2^30 was printed as 0.500MiB rather t= han > 512MiB. floor(log2(val)) is equal to 63 - clz(val), while the code use= d 64. >=20 > * The desired specification is %g rather than %f, which always uses thr= ee > decimals in the current code. However %g would switch to scientific > notation when the integer part is >=3D 1000 (e.g. 1000*2^30). To keep = the > code simple, switch to the higher power when the integer part is >=3D 1= 000; > overflow is avoided by using frexp instead of clz. >=20 > Suggested-by: Eric Blake > Signed-off-by: Paolo Bonzini > --- > qapi/string-output-visitor.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) >=20 > =20 > - out =3D g_strdup_printf("%0.03f%c", (double)val/div, suffixes[i]);= > + out =3D 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 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --vd8URthvRppcxXNPJeSPAsew6EFVTb78L Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJS6rMLAAoJEKeha0olJ0Nq2JEH/RRyLD08CJ0j4zxTWWn2yT0c cT4nA3KPi/MERQpDYz3iiJpFQNjnaL+mNWJqz+YQgcBZgMO+iMAbW3kDz1e1rMiN e9z2UyNTXHMrPQu82XYuSPTNTeaDmflNnOkv+rIXiS+uggFjOmAgQhosb2kB29kG izmytKKXhmqqWrtFYsDrjo/s9mCSyZ7ibz09JmRj8wNWk3G7C1XMYcaHQgkg06cT G5umD7xKFySAmPmi6M3AuL0O00rHyp229kt716iYIZ8BFcagpLuWpieERPLDp3qM aBuRD2ogppyxP6qZsEPrZhu8iCay/B/CGfBx+Jz7R5QB2uIDjp/ZFtMd30GIDM0= =HRYw -----END PGP SIGNATURE----- --vd8URthvRppcxXNPJeSPAsew6EFVTb78L--