mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 20:40:05 +00:00
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Parse thousand
separators also if no non-zero digits found. * stdlib/Makefile (tests): Add tst-strtod3.
This commit is contained in:
parent
f85fb97b9b
commit
1f55ce483b
@ -1,3 +1,9 @@
|
|||||||
|
2006-12-11 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Parse thousand
|
||||||
|
separators also if no non-zero digits found.
|
||||||
|
* stdlib/Makefile (tests): Add tst-strtod3.
|
||||||
|
|
||||||
2006-12-09 Ulrich Drepper <drepper@redhat.com>
|
2006-12-09 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
[BZ #3632]
|
[BZ #3632]
|
||||||
|
@ -67,7 +67,7 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \
|
|||||||
tst-xpg-basename tst-random tst-random2 tst-bsearch \
|
tst-xpg-basename tst-random tst-random2 tst-bsearch \
|
||||||
tst-limits tst-rand48 bug-strtod tst-setcontext \
|
tst-limits tst-rand48 bug-strtod tst-setcontext \
|
||||||
test-a64l tst-qsort tst-system testmb2 bug-strtod2 \
|
test-a64l tst-qsort tst-system testmb2 bug-strtod2 \
|
||||||
tst-atof1 tst-atof2 tst-strtod2
|
tst-atof1 tst-atof2 tst-strtod2 tst-strtod3
|
||||||
|
|
||||||
include ../Makeconfig
|
include ../Makeconfig
|
||||||
|
|
||||||
|
@ -721,7 +721,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc)
|
|||||||
c = *++cp;
|
c = *++cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grouping && dig_no > 0)
|
if (grouping && cp > start_of_digits)
|
||||||
{
|
{
|
||||||
/* Check the grouping of the digits. */
|
/* Check the grouping of the digits. */
|
||||||
#ifdef USE_WIDE_CHAR
|
#ifdef USE_WIDE_CHAR
|
||||||
|
19
stdlib/tst-atof1.c
Normal file
19
stdlib/tst-atof1.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
snprintf (buf, sizeof (buf), "%g", atof ("0x10p-1"));
|
||||||
|
if (strcmp (buf, "8") != 0)
|
||||||
|
{
|
||||||
|
printf ("got \"%s\", expected \"8\"\n", buf);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#include "../test-skeleton.c"
|
25
stdlib/tst-strtod2.c
Normal file
25
stdlib/tst-strtod2.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
const char s[] = "0x";
|
||||||
|
char *ep;
|
||||||
|
double r = strtod (s, &ep);
|
||||||
|
if (r != 0)
|
||||||
|
{
|
||||||
|
printf ("r = %g, expect 0\n", r);
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
if (ep != s + 1)
|
||||||
|
{
|
||||||
|
printf ("strtod parsed %ju characters, expected 1\n", ep - s);
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#include "../test-skeleton.c"
|
55
stdlib/tst-strtod3.c
Normal file
55
stdlib/tst-strtod3.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <locale.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
const char *in;
|
||||||
|
const char *out;
|
||||||
|
double expected;
|
||||||
|
} tests[] =
|
||||||
|
{
|
||||||
|
{ "000,,,e1", ",,,e1", 0.0 },
|
||||||
|
{ "000e1", "", 0.0 },
|
||||||
|
{ "000,1e1", ",1e1", 0.0 }
|
||||||
|
};
|
||||||
|
#define NTESTS (sizeof (tests) / sizeof (tests[0]))
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
|
||||||
|
{
|
||||||
|
puts ("could not set locale");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < NTESTS; ++i)
|
||||||
|
{
|
||||||
|
char *ep;
|
||||||
|
double r = __strtod_internal (tests[i].in, &ep, 1);
|
||||||
|
|
||||||
|
if (strcmp (ep, tests[i].out) != 0)
|
||||||
|
{
|
||||||
|
printf ("%d: got rest string \"%s\", expected \"%s\"\n",
|
||||||
|
i, ep, tests[i].out);
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r != 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"
|
Loading…
Reference in New Issue
Block a user