From patchwork Mon Mar 5 19:10:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 144760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 90AB3B6FA3 for ; Tue, 6 Mar 2012 06:42:13 +1100 (EST) Received: from localhost ([::1]:50181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4dKB-0000b7-3Y for incoming@patchwork.ozlabs.org; Mon, 05 Mar 2012 14:11:59 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4dJY-0007Nf-Og for qemu-devel@nongnu.org; Mon, 05 Mar 2012 14:11:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4dJB-0000Pt-IS for qemu-devel@nongnu.org; Mon, 05 Mar 2012 14:11:20 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:39020) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4dJB-0000NQ-Ai for qemu-devel@nongnu.org; Mon, 05 Mar 2012 14:10:57 -0500 Received: by mail-pw0-f45.google.com with SMTP id uo5so4717362pbc.4 for ; Mon, 05 Mar 2012 11:10:56 -0800 (PST) Received-SPF: pass (google.com: domain of flukshun@gmail.com designates 10.68.125.233 as permitted sender) client-ip=10.68.125.233; Authentication-Results: mr.google.com; spf=pass (google.com: domain of flukshun@gmail.com designates 10.68.125.233 as permitted sender) smtp.mail=flukshun@gmail.com; dkim=pass header.i=flukshun@gmail.com Received: from mr.google.com ([10.68.125.233]) by 10.68.125.233 with SMTP id mt9mr52509332pbb.119.1330974656594 (num_hops = 1); Mon, 05 Mar 2012 11:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=EunYutFc3dx4l0bYP6qzEPCWZDJYCmzabDC7U+fde2U=; b=HIci/0fA54k7G7xPZ3k9ApN6wTvP1z/QV/3YshzqGSQq/ZOjB6UQFVqap5XKtJ2HCt h6qIi2bAedciQwIdTC6cHuaJETdP7T9Aa4IGtqBdgnhIrpvAo0lJQbT2vLUCDMaYg0jp jtx2TzYnuzc8JdymPG8k93LpxZoq/K88rSE4xW4dybT4FEbtqiO+OjTsGcSGxB4qo8m6 NzQMi+hxO8VWIOiUEC+aN+B1A6KB3mvZFCXrwVfcm2uUeyXs/M/mBYRrjemRD07ZcHZn LWa5TjJw05pu5vLoBz23kSs9DO+UfYTB5FKULEW9cO0hqNrSedRgb0exBLq6HwQptzJA 6+6Q== Received: by 10.68.125.233 with SMTP id mt9mr44994948pbb.119.1330974656528; Mon, 05 Mar 2012 11:10:56 -0800 (PST) Received: from localhost.localdomain ([32.97.110.59]) by mx.google.com with ESMTPS id f7sm5117780pbr.3.2012.03.05.11.10.54 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Mar 2012 11:10:55 -0800 (PST) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2012 13:10:32 -0600 Message-Id: <1330974634-7527-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1330974634-7527-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1330974634-7527-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v3 5/7] qapi: String visitor, use %f represenation for floats X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 +- 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); }