math: brief readme
[libc-test] / src / math / sincos.c
1 #include <stdint.h>
2 #include <stdio.h>
3 #include "util.h"
4
5 static struct d_dd t[] = {
6 #include "sanity/sincos.h"
7 };
8
9 int main(void)
10 {
11         #pragma STDC FENV_ACCESS ON
12         double ysin, ycos;
13         float dsin, dcos;
14         int e, i, err = 0;
15         struct d_dd *p;
16
17         for (i = 0; i < sizeof t/sizeof *t; i++) {
18                 p = t + i;
19
20                 if (p->r < 0)
21                         continue;
22                 fesetround(p->r);
23                 feclearexcept(FE_ALL_EXCEPT);
24                 sincos(p->x, &ysin, &ycos);
25                 e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
26
27                 if (!checkexcept(e, p->e, p->r)) {
28                         printf("%s:%d: bad fp exception: %s sincos(%a)=%a,%a, want %s",
29                                 p->file, p->line, rstr(p->r), p->x, p->y, p->y2, estr(p->e));
30                         printf(" got %s\n", estr(e));
31                         err++;
32                 }
33                 dsin = ulperr(ysin, p->y, p->dy);
34                 dcos = ulperr(ycos, p->y2, p->dy2);
35                 if (!checkulp(dsin, p->r) || !checkulp(dcos, p->r)) {
36                         printf("%s:%d: %s sincos(%a) want %a,%a got %a,%a, ulperr %.3f = %a + %a, %.3f = %a + %a\n",
37                                 p->file, p->line, rstr(p->r), p->x, p->y, p->y2, ysin, ycos,
38                                 dsin, dsin-p->dy, p->dy, dcos, dcos-p->dy2, p->dy2);
39                         err++;
40                 }
41         }
42         return !!err;
43 }