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