fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / test / test.c
blob615c54aa5a4205ff51fedf67907ca73931951bb9
1 #include <signal.h>
2 #include "test.h"
3 #include <math.h>
4 #include <ieeefp.h>
5 #include <string.h>
6 int verbose;
7 static int count;
8 int inacc;
11 int
12 _DEFUN(main,(ac, av),
13 int ac _AND
14 char **av)
16 int i;
17 int math2 = 1;
18 int string= 1;
19 int is = 1;
20 int math= 1;
21 int cvt = 1;
22 int ieee= 1;
23 bt();
24 for (i = 1; i < ac; i++)
26 if (strcmp(av[i],"-v")==0)
27 verbose ++;
28 if (strcmp(av[i],"-nomath2") == 0)
29 math2 = 0;
30 if (strcmp(av[i],"-nostrin") == 0)
31 string= 0;
32 if (strcmp(av[i],"-nois") == 0)
33 is = 0;
34 if (strcmp(av[i],"-nomath") == 0)
35 math= 0;
36 if (strcmp(av[i],"-nocvt") == 0)
37 cvt = 0;
38 if (strcmp(av[i],"-noiee") == 0)
39 ieee= 0;
41 if (cvt)
42 test_cvt();
44 if (math2)
45 test_math2();
46 if (string)
47 test_string();
48 if (math)
49 test_math();
50 if (is)
51 test_is();
52 if (ieee) test_ieee();
53 printf("Tested %d functions, %d errors detected\n", count, inacc);
54 return 0;
58 static _CONST char *iname = "foo";
59 void
60 _DEFUN(newfunc,(string),
61 _CONST char *string)
63 if (strcmp(iname, string))
65 printf("testing %s\n", string);
66 fflush(stdout);
67 iname = string;
73 static int theline;
75 void line(li)
76 int li;
78 if (verbose)
80 printf(" %d\n", li);
82 theline = li;
84 count++;
89 int redo = 0;
90 int reduce = 0;
92 int strtod_vector = 0;
94 int
95 _DEFUN(bigger,(a,b),
96 __ieee_double_shape_type *a _AND
97 __ieee_double_shape_type *b)
100 if (a->parts.msw > b->parts.msw)
103 return 1;
105 else if (a->parts.msw == b->parts.msw)
107 if (a->parts.lsw > b->parts.lsw)
109 return 1;
112 return 0;
117 /* Return the first bit different between two double numbers */
118 int
119 _DEFUN(mag_of_error,(is, shouldbe),
120 double is _AND
121 double shouldbe)
123 __ieee_double_shape_type a,b;
124 int i;
125 int a_big;
126 unsigned int mask;
127 unsigned long int __x;
128 unsigned long int msw, lsw;
129 a.value = is;
131 b.value = shouldbe;
133 if (a.parts.msw == b.parts.msw
134 && a.parts.lsw== b.parts.lsw) return 64;
137 /* Subtract the larger from the smaller number */
139 a_big = bigger(&a, &b);
141 if (!a_big) {
142 int t;
143 t = a.parts.msw;
144 a.parts.msw = b.parts.msw;
145 b.parts.msw = t;
147 t = a.parts.lsw;
148 a.parts.lsw = b.parts.lsw;
149 b.parts.lsw = t;
154 __x = (a.parts.lsw) - (b.parts.lsw);
155 msw = (a.parts.msw) - (b.parts.msw) - (__x > (a.parts.lsw));
156 lsw = __x;
161 /* Find out which bit the difference is in */
162 mask = 0x80000000;
163 for (i = 0; i < 32; i++)
165 if (((msw) & mask)!=0) return i;
166 mask >>=1;
169 mask = 0x80000000;
170 for (i = 0; i < 32; i++)
173 if (((lsw) & mask)!=0) return i+32;
174 mask >>=1;
177 return 64;
181 int ok_mag;
185 void
186 _DEFUN(test_sok,(is, shouldbe),
187 char *is _AND
188 char *shouldbe)
190 if (strcmp(is,shouldbe))
192 printf("%s:%d, inacurate answer: (%s should be %s)\n",
193 iname,
194 theline,
195 is, shouldbe);
196 inacc++;
199 void
200 _DEFUN(test_iok,(is, shouldbe),
201 int is _AND
202 int shouldbe)
204 if (is != shouldbe){
205 printf("%s:%d, inacurate answer: (%08x should be %08x)\n",
206 iname,
207 theline,
208 is, shouldbe);
209 inacc++;
214 /* Compare counted strings upto a certain length - useful to test single
215 prec float conversions against double results
217 void
218 _DEFUN(test_scok,(is, shouldbe, count),
219 char *is _AND
220 char *shouldbe _AND
221 int count)
223 if (strncmp(is,shouldbe, count))
225 printf("%s:%d, inacurate answer: (%s should be %s)\n",
226 iname,
227 theline,
228 is, shouldbe);
229 inacc++;
233 void
234 _DEFUN(test_eok,(is, shouldbe),
235 int is _AND
236 int shouldbe)
238 if (is != shouldbe){
239 printf("%s:%d, bad errno answer: (%d should be %d)\n",
240 iname,
241 theline,
242 is, shouldbe);
243 inacc++;
247 void
248 _DEFUN(test_mok,(value, shouldbe, okmag),
249 double value _AND
250 double shouldbe _AND
251 int okmag)
253 __ieee_double_shape_type a,b;
254 int mag = mag_of_error(value, shouldbe);
255 if (mag == 0)
257 /* error in the first bit is ok if the numbers are both 0 */
258 if (value == 0.0 && shouldbe == 0.0)
259 return;
262 a.value = shouldbe;
263 b.value = value;
265 if (mag < okmag)
267 printf("%s:%d, wrong answer: bit %d ",
268 iname,
269 theline,
270 mag);
271 printf("%08x%08x %08x%08x) ",
272 a.parts.msw, a.parts.lsw,
273 b.parts.msw, b.parts.lsw);
274 printf("(%g %g)\n", a.value, b.value);
275 inacc++;
279 #ifdef __PCCNECV70__
280 kill() {}
281 getpid() {}
282 #endif
284 bt(){
286 double f1,f2;
287 f1 = 0.0;
288 f2 = 0.0/f1;
289 printf("(%g)\n", f2);