aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2002-04-27 05:01:54 +0800
committerChris Lahey <clahey@src.gnome.org>2002-04-27 05:01:54 +0800
commitde04a23ab78c1dbdf6dff57a462d55b77b527cfe (patch)
tree1d7c89b68cc5c34ab36a4752de8201ca2f62351e /e-util
parent68cb7c9340ccfac138652a0152be72bab7c211c7 (diff)
downloadgsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.tar
gsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.tar.gz
gsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.tar.bz2
gsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.tar.lz
gsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.tar.xz
gsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.tar.zst
gsoc2013-evolution-de04a23ab78c1dbdf6dff57a462d55b77b527cfe.zip
Use DBL_DIG to compute how much buffer space to use here.
2002-04-26 Christopher James Lahey <clahey@ximian.com> * 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
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-util.h3
-rw-r--r--e-util/e-xml-utils.c8
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 <sys/types.h>
#include <gtk/gtktypeutils.h>
+#include <limits.h>
#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);
}