From 11a87df2845c4cd577786d2b4df83ab44421f546 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 28 Feb 2012 07:45:50 +0000 Subject: Fix serialisation of decimals like 10.0, 20.0, etc. git-svn-id: http://svn.drobilla.net/serd/trunk@325 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/node.c | 2 +- tests/serd_test.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node.c b/src/node.c index 73976b44..4d8c620f 100644 --- a/src/node.c +++ b/src/node.c @@ -145,7 +145,7 @@ SerdNode serd_node_new_decimal(double d, unsigned frac_digits) { const double abs_d = fabs(d); - const unsigned int_digits = (unsigned)fmax(1.0, ceil(log10(abs_d))); + const unsigned int_digits = (unsigned)fmax(1.0, ceil(log10(abs_d + 1))); char* buf = (char*)calloc(int_digits + frac_digits + 3, 1); SerdNode node = { (const uint8_t*)buf, 0, 0, 0, SERD_LITERAL }; const double int_part = floor(abs_d); diff --git a/tests/serd_test.c b/tests/serd_test.c index aa47ade4..12129280 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -108,11 +108,11 @@ main() // Test serd_node_new_decimal const double dbl_test_nums[] = { - 0.0, 42.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001 + 0.0, 9.0, 10.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001 }; const char* dbl_test_strs[] = { - "0.0", "42.0", "0.01", "2.05", "-16.00001", "5.00000001", "0.0" + "0.0", "9.0", "10.0", "0.01", "2.05", "-16.00001", "5.00000001", "0.0" }; for (unsigned i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) { -- cgit v1.2.1