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