[libgsf] xml: do a better job of saving all precision.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsf] xml: do a better job of saving all precision.
- Date: Thu, 5 Mar 2015 03:22:57 +0000 (UTC)
commit 94b3a9ecd395de0abd9b2493bb29c33ff88a2d19
Author: Morten Welinder <terra gnome org>
Date: Wed Mar 4 22:22:29 2015 -0500
xml: do a better job of saving all precision.
ChangeLog | 5 +++++
NEWS | 3 +++
gsf/gsf-libxml.c | 17 +++++++++--------
3 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a3f5b24..3d43a1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-04 Morten Welinder <terra gnome org>
+
+ * gsf/gsf-libxml.c (gsf_xml_out_add_float): Do a better job of
+ saving all precision.
+
2015-03-04 Morten Welinder <terra gnome org>
* configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 181f1df..3bd40a7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
libgsf 1.14.33
+Morten:
+ * Ensure floats roundtrip through our xml functions.
+
--------------------------------------------------------------------------
libgsf 1.14.32
diff --git a/gsf/gsf-libxml.c b/gsf/gsf-libxml.c
index 5b820cf..7097fa9 100644
--- a/gsf/gsf-libxml.c
+++ b/gsf/gsf-libxml.c
@@ -1923,14 +1923,15 @@ void
gsf_xml_out_add_float (GsfXMLOut *xout, char const *id,
double val, int precision)
{
- char format_str[4 * sizeof (int) + 10];
- char buf[G_ASCII_DTOSTR_BUF_SIZE + DBL_DIG];
-
- if (precision < 0 || precision > DBL_DIG)
- precision = DBL_DIG;
-
- sprintf (format_str, "%%.%dg", precision);
- g_ascii_formatd (buf, sizeof (buf), format_str, val);
+ char buf[G_ASCII_DTOSTR_BUF_SIZE + DBL_DIG + 17];
+
+ if (precision < 0 || precision > 17) {
+ g_ascii_dtostr (buf, sizeof (buf), val);
+ } else {
+ char format_str[4 * sizeof (int) + 10];
+ sprintf (format_str, "%%.%dg", precision);
+ g_ascii_formatd (buf, sizeof (buf), format_str, val);
+ }
gsf_xml_out_add_cstr_unchecked (xout, id, buf);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]