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