1#define _XOPEN_SOURCE 700 2#include <stdint.h> 3#include <stdio.h> 4#include "mtest.h" 5 6static struct d_di t[] = { 7#include "sanity/lgamma.h" 8#include "special/lgamma.h" 9 10}; 11 12int main(void) 13{ 14 #pragma STDC FENV_ACCESS ON 15 int yi; 16 double y; 17 float d; 18 int e, i, bad, 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 bad = !isnan(p->x) && p->x!=-inf && !(p->e&DIVBYZERO) && yi != p->i; 40 if (bad || !checkulp(d, p->r)) { 41 if (!bad && fabsf(d) < 11.0f) 42 printf("X "); 43 else 44 err++; 45 printf("%s:%d: %s lgamma(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", 46 p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); 47 } 48 } 49 return !!err; 50} 51