From de04a23ab78c1dbdf6dff57a462d55b77b527cfe Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Fri, 26 Apr 2002 21:01:54 +0000 Subject: Use DBL_DIG to compute how much buffer space to use here. 2002-04-26 Christopher James Lahey * gal/util/e-util.h (E_ASCII_DTOSTR_BUF_SIZE): Use DBL_DIG to compute how much buffer space to use here. * gal/util/e-xml-utils.c (e_xml_set_double_prop_by_name): Use DBL_DIG here to decide how many digits to print. svn path=/trunk/; revision=16604 --- e-util/e-util.h | 3 ++- e-util/e-xml-utils.c | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/e-util/e-util.h b/e-util/e-util.h index 65a8d0d618..3df619a522 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -26,6 +26,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -188,7 +189,7 @@ gdouble e_flexible_strtod (cons /* 29 bytes should enough for all possible values that * g_ascii_dtostr can produce with the %.17g format. * Then add 10 for good measure */ -#define E_ASCII_DTOSTR_BUF_SIZE (29 + 10) +#define E_ASCII_DTOSTR_BUF_SIZE (DBL_DIG + 12 + 10) gchar *e_ascii_dtostr (gchar *buffer, gint buf_len, const gchar *format, diff --git a/e-util/e-xml-utils.c b/e-util/e-xml-utils.c index fa4f96c1a2..98c089074b 100644 --- a/e-util/e-xml-utils.c +++ b/e-util/e-xml-utils.c @@ -343,15 +343,19 @@ void e_xml_set_double_prop_by_name(xmlNode *parent, const xmlChar *prop_name, gdouble value) { char buffer[E_ASCII_DTOSTR_BUF_SIZE]; + char *format; g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); if (fabs (value) < 1e9 && fabs (value) > 1e-5) { - e_ascii_dtostr (buffer, sizeof (buffer), "%.17f", value); + format = g_strdup_printf ("%%.%df", DBL_DIG); } else { - e_ascii_dtostr (buffer, sizeof (buffer), "%.17g", value); + format = g_strdup_printf ("%%.%dg", DBL_DIG); } + e_ascii_dtostr (buffer, sizeof (buffer), format, value); + g_free (format); + xmlSetProp (parent, prop_name, buffer); } -- cgit v1.2.3