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
This commit is contained in:
Robert Ancell 2018-01-12 09:44:24 +13:00 committed by Iain Lane
parent e430541378
commit d870628782

View File

@ -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;
}