qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v2 5/6] qapi: String visitor, use %f represenation for floats
Date: Thu, 23 Feb 2012 14:22:25 -0600	[thread overview]
Message-ID: <1330028546-13183-6-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1330028546-13183-1-git-send-email-mdroth@linux.vnet.ibm.com>

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 <mdroth@linux.vnet.ibm.com>
---
 qapi/string-output-visitor.c |    2 +-
 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));
 }
 
 char *string_output_get_string(StringOutputVisitor *sov)
diff --git a/test-string-output-visitor.c b/test-string-output-visitor.c
index 22909b8..608f14a 100644
--- a/test-string-output-visitor.c
+++ b/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);
 }
 
-- 
1.7.4.1

  parent reply	other threads:[~2012-02-23 20:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23 20:22 [Qemu-devel] [PATCH v2 0/6] add fixed-width visitors and serialization tests Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 1/6] qapi: add Visitor interfaces for uint*_t and int*_t Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 2/6] qapi: unit tests for visitor-based serialization Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 3/6] qapi: QMP input visitor, handle floats parsed as ints Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 4/6] qapi: add String visitor coverage to serialization unit tests Michael Roth
2012-02-23 20:22 ` Michael Roth [this message]
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 6/6] qdev: switch property accessors to fixed-width visitor interfaces Michael Roth
2012-02-24 17:22   ` Anthony Liguori
2012-02-25 15:41     ` Michael Roth
2012-02-25 16:08       ` Andreas Färber
2012-02-25 20:33         ` Paolo Bonzini

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=1330028546-13183-6-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).