]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/tst-strtod5.c
Fix trailing space.
[thirdparty/glibc.git] / stdlib / tst-strtod5.c
CommitLineData
64f6281c
UD
1#include <locale.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <math.h>
6
7#define NBSP "\xc2\xa0"
8
9static const struct
10{
11 const char *in;
12 int group;
13 double expected;
14} tests[] =
15 {
16 { "0", 0, 0.0 },
17 { "000", 0, 0.0 },
18 { "-0", 0, -0.0 },
19 { "-000", 0, -0.0 },
20 { "0,", 0, 0.0 },
21 { "-0,", 0, -0.0 },
22 { "0,0", 0, 0.0 },
23 { "-0,0", 0, -0.0 },
24 { "0e-10", 0, 0.0 },
25 { "-0e-10", 0, -0.0 },
26 { "0,e-10", 0, 0.0 },
27 { "-0,e-10", 0, -0.0 },
28 { "0,0e-10", 0, 0.0 },
29 { "-0,0e-10", 0, -0.0 },
30 { "0e-1000000", 0, 0.0 },
31 { "-0e-1000000", 0, -0.0 },
32 { "0,0e-1000000", 0, 0.0 },
33 { "-0,0e-1000000", 0, -0.0 },
34 { "0", 1, 0.0 },
35 { "000", 1, 0.0 },
36 { "-0", 1, -0.0 },
37 { "-000", 1, -0.0 },
38 { "0e-10", 1, 0.0 },
39 { "-0e-10", 1, -0.0 },
40 { "0e-1000000", 1, 0.0 },
41 { "-0e-1000000", 1, -0.0 },
42 { "000"NBSP"000"NBSP"000", 1, 0.0 },
43 { "-000"NBSP"000"NBSP"000", 1, -0.0 }
44 };
45#define NTESTS (sizeof (tests) / sizeof (tests[0]))
46
47
48static int
49do_test (void)
50{
51 if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
52 {
53 puts ("could not set locale");
54 return 1;
55 }
56
57 int status = 0;
58
59 for (int i = 0; i < NTESTS; ++i)
60 {
61 char *ep;
62 double r;
63
64 if (tests[i].group)
65 r = __strtod_internal (tests[i].in, &ep, 1);
66 else
67 r = strtod (tests[i].in, &ep);
68
69 if (*ep != '\0')
70 {
71 printf ("%d: got rest string \"%s\", expected \"\"\n", i, ep);
72 status = 1;
73 }
74
75 if (r != tests[i].expected
76 || copysign (10.0, r) != copysign (10.0, tests[i].expected))
77 {
78 printf ("%d: got wrong results %g, expected %g\n",
79 i, r, tests[i].expected);
80 status = 1;
81 }
82 }
83
84 return status;
85}
86
87#define TEST_FUNCTION do_test ()
88#include "../test-skeleton.c"