[glib] gdatetime: Avoid repeated floating point multiplies with ISO 8601 parsing
- From: Iain Lane <iainl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gdatetime: Avoid repeated floating point multiplies with ISO 8601 parsing
- Date: Mon, 15 Jan 2018 12:00:27 +0000 (UTC)
commit d87062878235da4d6a652d504cfbce11137eba4c
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Jan 12 09:44:24 2018 +1300
gdatetime: Avoid repeated floating point multiplies with ISO 8601 parsing
This avoids any potential rounding errors.
https://bugzilla.gnome.org/show_bug.cgi?id=792410
glib/gdatetime.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 88af308..c74fa2a 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -928,7 +928,7 @@ static gboolean
get_iso8601_seconds (const gchar *text, gsize length, gdouble *value)
{
gint i;
- gdouble multiplier = 0.1, v = 0;
+ gdouble divisor = 1, v = 0;
if (length < 2)
return FALSE;
@@ -952,11 +952,11 @@ get_iso8601_seconds (const gchar *text, gsize length, gdouble *value)
const gchar c = text[i];
if (c < '0' || c > '9')
return FALSE;
- v += (c - '0') * multiplier;
- multiplier *= 0.1;
+ v = v * 10 + (c - '0');
+ divisor *= 10;
}
- *value = v;
+ *value = v / divisor;
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]