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