diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-08-03 16:45:47 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-08-03 16:45:47 +0000 |
commit | 64f6281cbb92c91989a51ca676eca245ea88228f (patch) | |
tree | 48f59140a01873ea839a1d0b5eea13577533f730 /stdlib/tst-strtod5.c | |
parent | ce31a3b1c588f8b8a5c7702c6460d6bd4386bd95 (diff) | |
download | glibc-64f6281cbb92c91989a51ca676eca245ea88228f.tar glibc-64f6281cbb92c91989a51ca676eca245ea88228f.tar.gz glibc-64f6281cbb92c91989a51ca676eca245ea88228f.tar.bz2 glibc-64f6281cbb92c91989a51ca676eca245ea88228f.zip |
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Properly handle -0.
* stdlib/Makefile (tests): Add tst-strtod5.
(tst-strtod5-ENV): New.
* stdlib/tst-strtod5.c: New file.
Diffstat (limited to 'stdlib/tst-strtod5.c')
-rw-r--r-- | stdlib/tst-strtod5.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/stdlib/tst-strtod5.c b/stdlib/tst-strtod5.c new file mode 100644 index 0000000000..337c746989 --- /dev/null +++ b/stdlib/tst-strtod5.c @@ -0,0 +1,88 @@ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#define NBSP "\xc2\xa0" + +static const struct +{ + const char *in; + int group; + double expected; +} tests[] = + { + { "0", 0, 0.0 }, + { "000", 0, 0.0 }, + { "-0", 0, -0.0 }, + { "-000", 0, -0.0 }, + { "0,", 0, 0.0 }, + { "-0,", 0, -0.0 }, + { "0,0", 0, 0.0 }, + { "-0,0", 0, -0.0 }, + { "0e-10", 0, 0.0 }, + { "-0e-10", 0, -0.0 }, + { "0,e-10", 0, 0.0 }, + { "-0,e-10", 0, -0.0 }, + { "0,0e-10", 0, 0.0 }, + { "-0,0e-10", 0, -0.0 }, + { "0e-1000000", 0, 0.0 }, + { "-0e-1000000", 0, -0.0 }, + { "0,0e-1000000", 0, 0.0 }, + { "-0,0e-1000000", 0, -0.0 }, + { "0", 1, 0.0 }, + { "000", 1, 0.0 }, + { "-0", 1, -0.0 }, + { "-000", 1, -0.0 }, + { "0e-10", 1, 0.0 }, + { "-0e-10", 1, -0.0 }, + { "0e-1000000", 1, 0.0 }, + { "-0e-1000000", 1, -0.0 }, + { "000"NBSP"000"NBSP"000", 1, 0.0 }, + { "-000"NBSP"000"NBSP"000", 1, -0.0 } + }; +#define NTESTS (sizeof (tests) / sizeof (tests[0])) + + +static int +do_test (void) +{ + if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL) + { + puts ("could not set locale"); + return 1; + } + + int status = 0; + + for (int i = 0; i < NTESTS; ++i) + { + char *ep; + double r; + + if (tests[i].group) + r = __strtod_internal (tests[i].in, &ep, 1); + else + r = strtod (tests[i].in, &ep); + + if (*ep != '\0') + { + printf ("%d: got rest string \"%s\", expected \"\"\n", i, ep); + status = 1; + } + + if (r != tests[i].expected + || copysign (10.0, r) != copysign (10.0, tests[i].expected)) + { + printf ("%d: got wrong results %g, expected %g\n", + i, r, tests[i].expected); + status = 1; + } + } + + return status; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |