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