math: add fenv pragma, relax the error check, simplify util.h
[libc-test] / src / math / scalb.c
1 #include <stdint.h>
2 #include <stdio.h>
3 #include "util.h"
4
5 static struct dd_d t[] = {
6
7 };
8
9 int main(void)
10 {
11         #pragma STDC FENV_ACCESS ON
12         double y;
13         float d;
14         int e, i, err = 0;
15         struct dd_d *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                 y = scalb(p->x, p->x2);
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 scalb(%a,%a)=%a, want %s",
29                                 p->file, p->line, rstr(p->r), p->x, p->x2, p->y, estr(p->e));
30                         printf(" got %s\n", estr(e));
31                         err++;
32                 }
33                 d = ulperr(y, p->y, p->dy);
34                 if (!checkulp(d, p->r)) {
35                         printf("%s:%d: %s scalb(%a,%a) want %a got %a ulperr %.3f = %a + %a\n",
36                                 p->file, p->line, rstr(p->r), p->x, p->x2, p->y, y, d, d-p->dy, p->dy);
37                         err++;
38                 }
39         }
40         return !!err;
41 }