Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / test / test.c
blob7769e2b368bc35309eb68f5bb93b9f4c11f19b51
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 main (int ac,
13 char **av)
15 int i;
16 int math2 = 1;
17 int string= 1;
18 int is = 1;
19 int math= 1;
20 int cvt = 1;
21 int ieee= 1;
22 bt();
23 for (i = 1; i < ac; i++)
25 if (strcmp(av[i],"-v")==0)
26 verbose ++;
27 if (strcmp(av[i],"-nomath2") == 0)
28 math2 = 0;
29 if (strcmp(av[i],"-nostrin") == 0)
30 string= 0;
31 if (strcmp(av[i],"-nois") == 0)
32 is = 0;
33 if (strcmp(av[i],"-nomath") == 0)
34 math= 0;
35 if (strcmp(av[i],"-nocvt") == 0)
36 cvt = 0;
37 if (strcmp(av[i],"-noiee") == 0)
38 ieee= 0;
40 if (cvt)
41 test_cvt();
43 if (math2)
44 test_math2();
45 if (string)
46 test_string();
47 if (math)
48 test_math();
49 if (is)
50 test_is();
51 if (ieee) test_ieee();
52 printf("Tested %d functions, %d errors detected\n", count, inacc);
53 return 0;
57 static const char *iname = "foo";
58 void
59 newfunc (const char *string)
61 if (strcmp(iname, string))
63 printf("testing %s\n", string);
64 fflush(stdout);
65 iname = string;
71 static int theline;
73 void line(li)
74 int li;
76 if (verbose)
78 printf(" %d\n", li);
80 theline = li;
82 count++;
87 int redo = 0;
88 int reduce = 0;
90 int strtod_vector = 0;
92 int
93 bigger (__ieee_double_shape_type *a,
94 __ieee_double_shape_type *b)
97 if (a->parts.msw > b->parts.msw)
100 return 1;
102 else if (a->parts.msw == b->parts.msw)
104 if (a->parts.lsw > b->parts.lsw)
106 return 1;
109 return 0;
114 /* Return the first bit different between two double numbers */
115 int
116 mag_of_error (double is,
117 double shouldbe)
119 __ieee_double_shape_type a,b;
120 int i;
121 int a_big;
122 unsigned int mask;
123 unsigned long int __x;
124 unsigned long int msw, lsw;
125 a.value = is;
127 b.value = shouldbe;
129 if (a.parts.msw == b.parts.msw
130 && a.parts.lsw== b.parts.lsw) return 64;
133 /* Subtract the larger from the smaller number */
135 a_big = bigger(&a, &b);
137 if (!a_big) {
138 int t;
139 t = a.parts.msw;
140 a.parts.msw = b.parts.msw;
141 b.parts.msw = t;
143 t = a.parts.lsw;
144 a.parts.lsw = b.parts.lsw;
145 b.parts.lsw = t;
150 __x = (a.parts.lsw) - (b.parts.lsw);
151 msw = (a.parts.msw) - (b.parts.msw) - (__x > (a.parts.lsw));
152 lsw = __x;
157 /* Find out which bit the difference is in */
158 mask = 0x80000000;
159 for (i = 0; i < 32; i++)
161 if (((msw) & mask)!=0) return i;
162 mask >>=1;
165 mask = 0x80000000;
166 for (i = 0; i < 32; i++)
169 if (((lsw) & mask)!=0) return i+32;
170 mask >>=1;
173 return 64;
177 int ok_mag;
181 void
182 test_sok (char *is,
183 char *shouldbe)
185 if (strcmp(is,shouldbe))
187 printf("%s:%d, inacurate answer: (%s should be %s)\n",
188 iname,
189 theline,
190 is, shouldbe);
191 inacc++;
194 void
195 test_iok (int is,
196 int shouldbe)
198 if (is != shouldbe){
199 printf("%s:%d, inacurate answer: (%08x should be %08x)\n",
200 iname,
201 theline,
202 is, shouldbe);
203 inacc++;
208 /* Compare counted strings upto a certain length - useful to test single
209 prec float conversions against double results
211 void
212 test_scok (char *is,
213 char *shouldbe,
214 int count)
216 if (strncmp(is,shouldbe, count))
218 printf("%s:%d, inacurate answer: (%s should be %s)\n",
219 iname,
220 theline,
221 is, shouldbe);
222 inacc++;
226 void
227 test_eok (int is,
228 int shouldbe)
230 if (is != shouldbe){
231 printf("%s:%d, bad errno answer: (%d should be %d)\n",
232 iname,
233 theline,
234 is, shouldbe);
235 inacc++;
239 void
240 test_mok (double value,
241 double shouldbe,
242 int okmag)
244 __ieee_double_shape_type a,b;
245 int mag = mag_of_error(value, shouldbe);
246 if (mag == 0)
248 /* error in the first bit is ok if the numbers are both 0 */
249 if (value == 0.0 && shouldbe == 0.0)
250 return;
253 a.value = shouldbe;
254 b.value = value;
256 if (mag < okmag)
258 printf("%s:%d, wrong answer: bit %d ",
259 iname,
260 theline,
261 mag);
262 printf("%08x%08x %08x%08x) ",
263 a.parts.msw, a.parts.lsw,
264 b.parts.msw, b.parts.lsw);
265 printf("(%g %g)\n", a.value, b.value);
266 inacc++;
270 #ifdef __PCCNECV70__
271 kill() {}
272 getpid() {}
273 #endif
275 bt(){
277 double f1,f2;
278 f1 = 0.0;
279 f2 = 0.0/f1;
280 printf("(%g)\n", f2);