Check for SYS/GL during library init. Reason is that
[AROS.git] / test / clib / strtod.c
blob40d18bb30101b7f050098d7490b9082438d1743f
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdlib.h>
7 #include <stdio.h>
9 const char * strings [] =
11 "1e1",
12 "1.2e2",
13 ".1e3",
14 ".e4",
15 "exp",
16 "e",
17 "12e ",
18 "12.1ef",
19 "12.e1",
20 "12.e",
21 "10.",
22 "10e+2",
23 "1000e-2",
24 "20e+ ",
25 "20e- ",
26 "-exp",
27 "+dummy",
28 "+10",
29 "-12.1e",
30 "-.e+4",
31 "-.1e+3",
32 NULL
35 const double results [] =
37 10.0,
38 120.0,
39 100.0,
40 0.0,
41 0.0,
42 0.0,
43 12.0,
44 12.1,
45 120,
46 12,
47 10,
48 1000,
49 10,
50 20,
51 20,
54 10.0,
55 -12.1,
57 -100.0,
60 const int ptroffset [] =
85 const char * newlinetest_rn = "\t-2.700264 -1.792122 -2.037897\r\n\t-0.084267 0.081827 0.584534\r\n";
86 const char * newlinetest_n = "\t-2.700264 -1.792122 -2.037897\n\t-0.084267 0.081827 0.584534\n";
88 const double newlinetestresults [] =
90 -2.700264,
91 -1.792122,
92 -2.037897,
93 -0.084267,
94 0.081827,
95 0.584534,
96 0.000000
99 const int newlinetestptroffset_rn [] =
112 const int newlinetestptroffset_n [] =
125 #define TESTLINELINE_I 6
127 void testnewline(const char * buffer, const int * ptroffset)
129 int i = 0; char * src = NULL; char *next;
130 for(src = (char *)buffer; i < (TESTLINELINE_I + 2); i++, src = next)
132 double f = strtod(src, &next);
133 if ((float)newlinetestresults[i] != (float)f)
134 printf("RESULT FAILURE @ %s, should be %f was %f\n", src, newlinetestresults[i], f);
135 if (ptroffset[i] != (next - src))
136 printf("OFFSET FAILURE @ %s, should be %d was %d\n", src, ptroffset[i], (int)(next - src));
137 if(next <= src) break;
140 if (TESTLINELINE_I != i)
141 printf("ITER FAILURE @ %s, should be %d was %d\n", buffer, TESTLINELINE_I, i);
144 int main()
146 char * float_end = NULL;
147 double f = 0;
148 int i = 0;
149 const char * str = NULL;
151 while((str = strings[i]) != NULL)
153 f = strtod(str, &float_end);
154 if (f != results[i])
155 printf("RESULT FAILURE @ %s, should be %f was %f\n", str, results[i], f);
156 if ((float_end - str) != ptroffset[i])
157 printf("OFFSET FAILURE @ %s, should be %d was %d\n", str, ptroffset[i], (int)(float_end - str));
158 i++;
161 /* Check bahavior with new-lined strings */
162 testnewline(newlinetest_rn, newlinetestptroffset_rn);
163 testnewline(newlinetest_n, newlinetestptroffset_n);
165 return 0;