mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 04:36:17 +01:00
Portability fixes and extra sanity checks. (#157453, Morten Welinder)
2004-11-05 Matthias Clasen <mclasen@redhat.com> * tests/strtod-test.c: Portability fixes and extra sanity checks. (#157453, Morten Welinder)
This commit is contained in:
parent
955c9a052a
commit
8bad5bfa3b
@ -1,3 +1,8 @@
|
|||||||
|
2004-11-05 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/strtod-test.c: Portability fixes and extra sanity
|
||||||
|
checks. (#157453, Morten Welinder)
|
||||||
|
|
||||||
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-11-05 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/strtod-test.c: Portability fixes and extra sanity
|
||||||
|
checks. (#157453, Morten Welinder)
|
||||||
|
|
||||||
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-11-05 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/strtod-test.c: Portability fixes and extra sanity
|
||||||
|
checks. (#157453, Morten Welinder)
|
||||||
|
|
||||||
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-11-05 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/strtod-test.c: Portability fixes and extra sanity
|
||||||
|
checks. (#157453, Morten Welinder)
|
||||||
|
|
||||||
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-11-05 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/strtod-test.c: Portability fixes and extra sanity
|
||||||
|
checks. (#157453, Morten Welinder)
|
||||||
|
|
||||||
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
2004-11-04 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
* glib/gstrfuncs.c (g_ascii_strtod): Handle numbers like
|
||||||
|
@ -16,7 +16,6 @@ test_string (char *number, double res, gboolean check_end, int correct_len)
|
|||||||
double d;
|
double d;
|
||||||
char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
|
char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
|
||||||
int l;
|
int l;
|
||||||
char *end;
|
|
||||||
char *dummy;
|
char *dummy;
|
||||||
|
|
||||||
/* we try a copy of number, with some free space for malloc before that.
|
/* we try a copy of number, with some free space for malloc before that.
|
||||||
@ -28,22 +27,32 @@ test_string (char *number, double res, gboolean check_end, int correct_len)
|
|||||||
|
|
||||||
for (l = 0; l < G_N_ELEMENTS (locales); l++)
|
for (l = 0; l < G_N_ELEMENTS (locales); l++)
|
||||||
{
|
{
|
||||||
|
gboolean ok;
|
||||||
|
char *end = "(unset)";
|
||||||
|
|
||||||
setlocale (LC_NUMERIC, locales[l]);
|
setlocale (LC_NUMERIC, locales[l]);
|
||||||
d = g_ascii_strtod (number, &end);
|
d = g_ascii_strtod (number, &end);
|
||||||
if ((isfinite(d) && isfinite(res) && d != res) ||
|
ok = isnan (res) ? isnan (d) : (d == res);
|
||||||
(isnan (d) != isnan (res)) ||
|
if (!ok)
|
||||||
(isinf (d) != isinf (res)))
|
|
||||||
{
|
{
|
||||||
g_print ("g_ascii_strtod on \"%s\" for locale %s failed\n", number, locales[l]);
|
g_print ("g_ascii_strtod on \"%s\" for locale %s failed\n", number, locales[l]);
|
||||||
g_print ("expected %lf (nan %d inf %d) actual %lf (nan %d inf %d)\n",
|
g_print ("expected %f (nan %d) actual %f (nan %d)\n",
|
||||||
res, isnan (res), isinf (res),
|
res, isnan (res),
|
||||||
d, isnan (d), isinf (d));
|
d, isnan (d));
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = (end - number) == (check_end ? correct_len : strlen (number));
|
||||||
|
if (!ok) {
|
||||||
|
if (end == NULL)
|
||||||
|
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was NULL\n",
|
||||||
|
number, locales[l]);
|
||||||
|
else if (end >= number && end <= number + strlen (number))
|
||||||
|
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was wrong, leftover: \"%s\"\n",
|
||||||
|
number, locales[l], end);
|
||||||
|
else
|
||||||
|
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was REALLY wrong (number=%p, end=%p)\n",
|
||||||
|
number, locales[l], number, end);
|
||||||
}
|
}
|
||||||
if (check_end && end - number != correct_len)
|
|
||||||
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was wrong, leftover: %s\n", number, locales[l], end);
|
|
||||||
if (!check_end && end - number != strlen (number))
|
|
||||||
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was wrong, leftover: %s\n", number, locales[l], end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (number);
|
g_free (number);
|
||||||
@ -53,9 +62,24 @@ test_string (char *number, double res, gboolean check_end, int correct_len)
|
|||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
gdouble d;
|
gdouble d, our_nan, our_inf;
|
||||||
char buffer[G_ASCII_DTOSTR_BUF_SIZE];
|
char buffer[G_ASCII_DTOSTR_BUF_SIZE];
|
||||||
|
|
||||||
|
#ifdef NAN
|
||||||
|
our_nan = NAN;
|
||||||
|
#else
|
||||||
|
/* Do this before any call to setlocale. */
|
||||||
|
our_nan = atof ("NaN");
|
||||||
|
#endif
|
||||||
|
g_assert (isnan (our_nan));
|
||||||
|
|
||||||
|
#ifdef INFINITY
|
||||||
|
our_inf = INFINITY;
|
||||||
|
#else
|
||||||
|
our_inf = atof ("Infinity");
|
||||||
|
#endif
|
||||||
|
g_assert (our_inf > 1 && our_inf == our_inf / 2);
|
||||||
|
|
||||||
test_string ("123.123", 123.123, FALSE, 0);
|
test_string ("123.123", 123.123, FALSE, 0);
|
||||||
test_string ("123.123e2", 123.123e2, FALSE, 0);
|
test_string ("123.123e2", 123.123e2, FALSE, 0);
|
||||||
test_string ("123.123e-2", 123.123e-2, FALSE, 0);
|
test_string ("123.123e-2", 123.123e-2, FALSE, 0);
|
||||||
@ -67,10 +91,10 @@ main ()
|
|||||||
test_string ("5,4", 5.0, TRUE, 1);
|
test_string ("5,4", 5.0, TRUE, 1);
|
||||||
/* the following are for #156421 */
|
/* the following are for #156421 */
|
||||||
test_string ("1e1", 1e1, FALSE, 0);
|
test_string ("1e1", 1e1, FALSE, 0);
|
||||||
test_string ("NAN", NAN, FALSE, 0);
|
test_string ("NAN", our_nan, FALSE, 0);
|
||||||
test_string ("-nan", -NAN, FALSE, 0);
|
test_string ("-nan", -our_nan, FALSE, 0);
|
||||||
test_string ("INF", INFINITY, FALSE, 0);
|
test_string ("INF", our_inf, FALSE, 0);
|
||||||
test_string ("-infinity", -INFINITY, FALSE, 0);
|
test_string ("-infinity", -our_inf, FALSE, 0);
|
||||||
|
|
||||||
d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
||||||
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
||||||
|
Loading…
Reference in New Issue
Block a user