[json-glib] generator: Use g_ascii_dtostr() to avoid losing precision



commit 02dd77efaa60201f74349c969dc005c8bb092057
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Jan 10 10:45:39 2011 +0000

    generator: Use g_ascii_dtostr() to avoid losing precision
    
    The nice format escape for g_ascii_formatd() is not really suited for a
    serialization format, as it obviously loses precision.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=637244

 json-glib/json-generator.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c
index 22fc6b3..c3bdc9a 100644
--- a/json-glib/json-generator.c
+++ b/json-glib/json-generator.c
@@ -316,10 +316,11 @@ dump_value (JsonGenerator *generator,
 
     case G_TYPE_DOUBLE:
       {
-        gchar buf[65];
+        gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
 
-        g_ascii_formatd (buf, 65, "%g", g_value_get_double (&value));
-        g_string_append (buffer, buf);
+        g_string_append (buffer,
+                         g_ascii_dtostr (buf, sizeof (buf),
+                                         g_value_get_double (&value)));
       }
       break;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]