math: add fenv pragma, relax the error check, simplify util.h
[libc-test] / src / math / log10l.c
1 #include <stdint.h>
2 #include <stdio.h>
3 #include "util.h"
4
5 static struct l_l t[] = {
6 #if LDBL_MANT_DIG == 53
7 #include "crlibm/log10.h"
8 #include "ucb/log10.h"
9 #include "sanity/log10.h"
10
11 #elif LDBL_MANT_DIG == 64
12 #include "sanity/log10l.h"
13
14 #endif
15 };
16
17 int main(void)
18 {
19         #pragma STDC FENV_ACCESS ON
20         long double y;
21         float d;
22         int e, i, err = 0;
23         struct l_l *p;
24
25         for (i = 0; i < sizeof t/sizeof *t; i++) {
26                 p = t + i;
27
28                 if (p->r < 0)
29                         continue;
30                 fesetround(p->r);
31                 feclearexcept(FE_ALL_EXCEPT);
32                 y = log10l(p->x);
33                 e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
34
35                 if (!checkexcept(e, p->e, p->r)) {
36                         printf("%s:%d: bad fp exception: %s log10l(%La)=%La, want %s",
37                                 p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e));
38                         printf(" got %s\n", estr(e));
39                         err++;
40                 }
41                 d = ulperrl(y, p->y, p->dy);
42                 if (!checkulp(d, p->r)) {
43                         printf("%s:%d: %s log10l(%La) want %La got %La ulperr %.3f = %a + %a\n",
44                                 p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy);
45                         err++;
46                 }
47         }
48         return !!err;
49 }