From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:32793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSsp8-0000zM-3L for qemu-devel@nongnu.org; Fri, 11 May 2012 12:36:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSsp6-00060K-1z for qemu-devel@nongnu.org; Fri, 11 May 2012 12:36:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSsp5-000607-PQ for qemu-devel@nongnu.org; Fri, 11 May 2012 12:36:07 -0400 Date: Fri, 11 May 2012 13:34:01 -0300 From: Luiz Capitulino Message-ID: <20120511133401.7599b6ba@doriath.home> In-Reply-To: <1335558083-26196-5-git-send-email-mdroth@linux.vnet.ibm.com> References: <1335558083-26196-1-git-send-email-mdroth@linux.vnet.ibm.com> <1335558083-26196-5-git-send-email-mdroth@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 4/7] qapi: String visitor, use %f represenation for floats List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: pbonzini@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, afaerber@suse.de On Fri, 27 Apr 2012 15:21:20 -0500 Michael Roth wrote: > Currently string-output-visitor formats floats as %g, which is nice in > that trailing 0's are automatically truncated, but otherwise this causes > some issues: > > - it 6 uses significant figures instead of 6 decimal places, which > means something like 155777.5 (which even has an exact floating point > representation) will be rounded to 155778 when converted to a string. > > - output will be presented in scientific notation when the normalized > form requires a 10^x multiplier. Not a huge deal, but arguably less > readable for command-line arguments. > > - due to using sig figs instead of hard-defined decimal places, it > fails a lot of the test-visitor-serialization unit tests for floats. > > Instead, let's just use %f, which is what the QJSON and the QMP visitors > use. > > Signed-off-by: Michael Roth > --- > qapi/string-output-visitor.c | 2 +- > tests/test-string-output-visitor.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c > index 92b0305..34e525e 100644 > --- a/qapi/string-output-visitor.c > +++ b/qapi/string-output-visitor.c > @@ -52,7 +52,7 @@ static void print_type_number(Visitor *v, double *obj, const char *name, > Error **errp) > { > StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); > - string_output_set(sov, g_strdup_printf("%g", *obj)); > + string_output_set(sov, g_strdup_printf("%f", *obj)); Doesn't look like a bug fix worth it for 1.1, am I wrong? > } > > char *string_output_get_string(StringOutputVisitor *sov) > diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c > index 22909b8..608f14a 100644 > --- a/tests/test-string-output-visitor.c > +++ b/tests/test-string-output-visitor.c > @@ -84,7 +84,7 @@ static void test_visitor_out_number(TestOutputVisitorData *data, > > str = string_output_get_string(data->sov); > g_assert(str != NULL); > - g_assert_cmpstr(str, ==, "3.14"); > + g_assert_cmpstr(str, ==, "3.140000"); > g_free(str); > } >