mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-30 20:33:08 +02: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)
|
get_iso8601_seconds (const gchar *text, gsize length, gdouble *value)
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
gdouble multiplier = 0.1, v = 0;
|
gdouble divisor = 1, v = 0;
|
||||||
|
|
||||||
if (length < 2)
|
if (length < 2)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -952,11 +952,11 @@ get_iso8601_seconds (const gchar *text, gsize length, gdouble *value)
|
|||||||
const gchar c = text[i];
|
const gchar c = text[i];
|
||||||
if (c < '0' || c > '9')
|
if (c < '0' || c > '9')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
v += (c - '0') * multiplier;
|
v = v * 10 + (c - '0');
|
||||||
multiplier *= 0.1;
|
divisor *= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
*value = v;
|
*value = v / divisor;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user