[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/8] qapi: String visitor, use %f representation for
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PATCH 3/8] qapi: String visitor, use %f representation for floats |
Date: |
Fri, 8 Jun 2012 17:35:08 +0200 |
From: Michael Roth <address@hidden>
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 uses 6 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 scientific notation for numbers requiring more than 6
significant figures, 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 <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
---
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));
}
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);
}
--
1.7.7
- [Qemu-devel] [PULL] qom-next queue, first batch: fixed-width visitors, Andreas Färber, 2012/06/08
- [Qemu-devel] [PATCH 5/8] qdev: Use int32_t container for devfn property, Andreas Färber, 2012/06/08
- [Qemu-devel] [PATCH 3/8] qapi: String visitor, use %f representation for floats,
Andreas Färber <=
- [Qemu-devel] [PATCH 4/8] qapi: Add String visitor coverage to serialization unit tests, Andreas Färber, 2012/06/08
- [Qemu-devel] [PATCH 8/8] target-i386: Use uint32 visitor for [x]level properties, Andreas Färber, 2012/06/08
- [Qemu-devel] [PATCH 6/8] qdev: Switch property accessors to fixed-width visitor interfaces, Andreas Färber, 2012/06/08
- [Qemu-devel] [PATCH 1/8] qapi: Add Visitor interfaces for uint*_t and int*_t, Andreas Färber, 2012/06/08
[Qemu-devel] [PATCH 2/8] qapi: Unit tests for visitor-based serialization, Andreas Färber, 2012/06/08
[Qemu-devel] [PATCH 7/8] qdev: Remove PropertyInfo range checking, Andreas Färber, 2012/06/08