Let GRUB text/graphics choice default to same as on boot media.
[AROS.git] / test / clib / strtod.c
blob1e62a80d453c0443397afae1c4e95f088c716508
1 #include <stdlib.h>
2 #include <stdio.h>
4 const char * strings [] =
6 "1e1",
7 "1.2e2",
8 ".1e3",
9 ".e4",
10 "exp",
11 "e",
12 "12e ",
13 "12.1ef",
14 "12.e1",
15 "12.e",
16 "10.",
17 "10e+2",
18 "1000e-2",
19 "20e+ ",
20 "20e- ",
21 "-exp",
22 "+dummy",
23 "+10",
24 "-12.1e",
25 "-.e+4",
26 "-.1e+3",
27 NULL
30 const double results [] =
32 10.0,
33 120.0,
34 100.0,
35 0.0,
36 0.0,
37 0.0,
38 12.0,
39 12.1,
40 120,
41 12,
42 10,
43 1000,
44 10,
45 20,
46 20,
49 10.0,
50 -12.1,
52 -100.0,
55 const int ptroffset [] =
80 const char * newlinetest_rn = "\t-2.700264 -1.792122 -2.037897\r\n\t-0.084267 0.081827 0.584534\r\n";
81 const char * newlinetest_n = "\t-2.700264 -1.792122 -2.037897\n\t-0.084267 0.081827 0.584534\n";
83 const double newlinetestresults [] =
85 -2.700264,
86 -1.792122,
87 -2.037897,
88 -0.084267,
89 0.081827,
90 0.584534,
91 0.000000
94 const int newlinetestptroffset_rn [] =
96 10,
97 10,
98 10,
99 12,
107 const int newlinetestptroffset_n [] =
120 #define TESTLINELINE_I 6
122 void testnewline(const char * buffer, const int * ptroffset)
124 int i = 0; char * src = NULL; char *next;
125 for(src = (char *)buffer; i < (TESTLINELINE_I + 2); i++, src = next)
127 double f = strtod(src, &next);
128 if ((float)newlinetestresults[i] != (float)f)
129 printf("RESULT FAILURE @ %s, should be %f was %f\n", src, newlinetestresults[i], f);
130 if (ptroffset[i] != (next - src))
131 printf("OFFSET FAILURE @ %s, should be %d was %d\n", src, ptroffset[i], (int)(next - src));
132 if(next <= src) break;
135 if (TESTLINELINE_I != i)
136 printf("ITER FAILURE @ %s, should be %d was %d\n", buffer, TESTLINELINE_I, i);
139 int main()
141 char * float_end = NULL;
142 double f = 0;
143 int i = 0;
144 const char * str = NULL;
146 while((str = strings[i]) != NULL)
148 f = strtod(str, &float_end);
149 if (f != results[i])
150 printf("RESULT FAILURE @ %s, should be %f was %f\n", str, results[i], f);
151 if ((float_end - str) != ptroffset[i])
152 printf("OFFSET FAILURE @ %s, should be %d was %d\n", str, ptroffset[i], (int)(float_end - str));
153 i++;
156 /* Check bahavior with new-lined strings */
157 testnewline(newlinetest_rn, newlinetestptroffset_rn);
158 testnewline(newlinetest_n, newlinetestptroffset_n);
160 return 0;