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