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