2 Test the library maths functions using trusted precomputed test
5 These vectors were originally generated on a sun3 with a 68881 using
6 80 bit precision, but ...
8 Each function is called with a variety of interesting arguments.
9 Note that many of the polynomials we use behave badly when the
10 domain is stressed, so the numbers in the vectors depend on what is
11 useful to test - eg sin(1e30) is pointless - the arg has to be
12 reduced modulo pi, and after that there's no bits of significance
13 left to evaluate with - any number would be just as precise as any
32 void translate_to (FILE *file
,
35 __ieee_double_shape_type bits
;
37 fprintf(file
, "0x%08x, 0x%08x", bits
.parts
.msw
, bits
.parts
.lsw
);
47 /* Make sure the answer isn't to far wrong from the correct value */
48 __ieee_double_shape_type correct
, isbits
;
52 correct
.parts
.msw
= p
->qs
[0].msw
;
53 correct
.parts
.lsw
= p
->qs
[0].lsw
;
55 mag
= mag_of_error(correct
.value
, is
);
57 if (mag
< p
->error_bit
)
61 printf("%s:%d, inaccurate answer: bit %d (%08x%08x %08x%08x) (%g %g)\n",
71 if (p
->qs
[0].merror
!= merror
)
73 /* Beware, matherr doesn't exist anymore. */
74 printf("testing %s_vec.c:%d, matherr wrong: %d %d\n",
75 name
, p
->line
, merror
, p
->qs
[0].merror
);
78 if (p
->qs
[0].errno_val
!= errno
)
80 printf("testing %s_vec.c:%d, errno wrong: %d %d\n",
81 name
, p
->line
, errno
, p
->qs
[0].errno_val
);
92 __ieee_double_shape_type x
;
111 if (reduce
&& p
->error_bit
< mag
)
113 fprintf(f
, "{%2d,", p
->error_bit
);
117 fprintf(f
, "{%2d,",mag
);
121 fprintf(f
,"%2d,%3d,", merror
,errno
);
122 fprintf(f
, "__LINE__, ");
126 translate_to(f
, result
);
130 translate_to(f
, thedouble(p
->qs
[0].msw
, p
->qs
[0].lsw
));
135 fprintf(f
,"0x%08x, 0x%08x", p
->qs
[1].msw
, p
->qs
[1].lsw
);
141 fprintf(f
,"0x%08x, 0x%08x", p
->qs
[2].msw
, p
->qs
[2].lsw
);
144 fprintf(f
,"}, /* %g=f(%g",result
,
145 thedouble(p
->qs
[1].msw
, p
->qs
[1].lsw
));
149 fprintf(f
,", %g", thedouble(p
->qs
[2].msw
,p
->qs
[2].lsw
));
163 mag
= ffcheck(result
, p
,name
, merror
, errno
);
166 frontline(f
, mag
, p
, result
, merror
, errno
, args
, name
);
170 run_vector_1 (int vector
,
189 for (k
= -.2; k
< .2; k
+= 0.00132)
192 fprintf(f
,"{1,1, 1,1, 0,0,0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
197 for (k
= -1.2; k
< 1.2; k
+= 0.01)
200 fprintf(f
,"{1,1, 1,1, 0,0,0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
204 for (k
= -M_PI
*2; k
< M_PI
*2; k
+= M_PI
/2)
207 fprintf(f
,"{1,1, 1,1, 0,0,0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
212 for (k
= -30; k
< 30; k
+= 1.7)
215 fprintf(f
,"{2,2, 1,1, 0,0, 0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
219 VECCLOSE(f
, name
, args
);
227 double arg1
= thedouble(p
->qs
[1].msw
, p
->qs
[1].lsw
);
228 double arg2
= thedouble(p
->qs
[2].msw
, p
->qs
[2].lsw
);
243 if (strcmp(args
,"dd")==0)
245 typedef double (*pdblfunc
) (double);
247 /* Double function returning a double */
249 result
= ((pdblfunc
)(func
))(arg1
);
251 finish(f
,vector
, result
, p
, args
, name
);
253 else if (strcmp(args
,"ff")==0)
258 typedef float (*pdblfunc
) (float);
260 /* Double function returning a double */
265 result
= ((pdblfunc
)(func
))(arga
);
266 finish(f
, vector
, result
, p
,args
, name
);
269 else if (strcmp(args
,"ddd")==0)
271 typedef double (*pdblfunc
) (double,double);
273 result
= ((pdblfunc
)(func
))(arg1
,arg2
);
274 finish(f
, vector
, result
, p
,args
, name
);
276 else if (strcmp(args
,"fff")==0)
283 typedef float (*pdblfunc
) (float,float);
286 if (arg1
< FLT_MAX
&& arg2
< FLT_MAX
)
290 result
= ((pdblfunc
)(func
))(arga
, argb
);
291 finish(f
, vector
, result
, p
,args
, name
);
294 else if (strcmp(args
,"did")==0)
296 typedef double (*pdblfunc
) (int,double);
298 result
= ((pdblfunc
)(func
))((int)arg1
,arg2
);
299 finish(f
, vector
, result
, p
,args
, name
);
301 else if (strcmp(args
,"fif")==0)
308 typedef float (*pdblfunc
) (int,float);
311 if (arg1
< FLT_MAX
&& arg2
< FLT_MAX
)
315 result
= ((pdblfunc
)(func
))((int)arga
, argb
);
316 finish(f
, vector
, result
, p
,args
, name
);
324 VECCLOSE(f
, name
, args
);
399 /* These have to be played with to get to compile on machines which
400 don't have the fancy <foo>f entry points
404 float cosf (float a
) { return cos((double)a
); }
405 float sinf (float a
) { return sin((double)a
); }
406 float log1pf (float a
) { return log1p((double)a
); }
407 float tanf (float a
) { return tan((double)a
); }
408 float ceilf (float a
) { return ceil(a
); }
409 float floorf (float a
) { return floor(a
); }
415 float fmodf(a
,b
) float a
,b
; { return fmod(a
,b
); }
416 float hypotf(a
,b
) float a
,b
; { return hypot(a
,b
); }
418 float acosf(a
) float a
; { return acos(a
); }
419 float acoshf(a
) float a
; { return acosh(a
); }
420 float asinf(a
) float a
; { return asin(a
); }
421 float asinhf(a
) float a
; { return asinh(a
); }
422 float atanf(a
) float a
; { return atan(a
); }
423 float atanhf(a
) float a
; { return atanh(a
); }
425 float coshf(a
) float a
; { return cosh(a
); }
426 float erff(a
) float a
; { return erf(a
); }
427 float erfcf(a
) float a
; { return erfc(a
); }
428 float expf(a
) float a
; { return exp(a
); }
429 float fabsf(a
) float a
; { return fabs(a
); }
431 float gammaf(a
) float a
; { return gamma(a
); }
432 float j0f(a
) float a
; { return j0(a
); }
433 float j1f(a
) float a
; { return j1(a
); }
434 float log10f(a
) float a
; { return log10(a
); }
436 float logf(a
) float a
; { return log(a
); }
438 float sinhf(a
) float a
; { return sinh(a
); }
439 float sqrtf(a
) float a
; { return sqrt(a
); }
441 float tanhf(a
) float a
; { return tanh(a
); }
442 float y0f(a
) float a
; { return y0(a
); }
443 float y1f(a
) float a
; { return y1(a
); }