mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-27 18:10:03 +01:00
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:
parent
e430541378
commit
d870628782
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user