add ere backref regression test
[libc-test] / src / math / modf.c
index 43b8657..b724650 100644 (file)
@@ -1,90 +1,44 @@
+#include <stdint.h>
 #include <stdio.h>
-#include <math.h>
-#include "test.h"
+#include "mtest.h"
 
-static struct {
-       double x;
-       double yf;
-       double yi;
-} t[] = {
-       0.7, 0x1.6666666666666p-1, 0.0,
-       -0.7, -0x1.6666666666666p-1, -0.0,
-       1.7, 0x1.6666666666666p-1, 1.0,
-       -1.7, -0x1.6666666666666p-1, -1.0,
-       2.0, 0.0, 2.0,
-       -2.0, -0.0, -2.0,
-       -0x1p99, -0.0, -0x1p99,
-       -0.0, -0.0, -0.0,
-       INFINITY, 0.0, INFINITY,
-       -INFINITY, -0.0, -INFINITY,
-       NAN, NAN, NAN,
+static struct d_dd t[] = {
+#include "sanity/modf.h"
+#include "special/modf.h"
 };
 
-static struct {
-       float x;
-       float yf;
-       float yi;
-} tf[] = {
-       0.7, 0x1.666666p-1, 0.0,
-       -0.7, -0x1.666666p-1, -0.0,
-       1.7, 0x1.666668p-1, 1.0,
-       -1.7, -0x1.666668p-1, -1.0,
-       2.0, 0.0, 2.0,
-       -2.0, -0.0, -2.0,
-       -0x1p99, -0.0, -0x1p99,
-       -0.0, -0.0, -0.0,
-       INFINITY, 0.0, INFINITY,
-       -INFINITY, -0.0, -INFINITY,
-       NAN, NAN, NAN,
-};
+int main(void)
+{
+       #pragma STDC FENV_ACCESS ON
+       double y, yi;
+       float d, di;
+       int e, i, err = 0;
+       struct d_dd *p;
 
-static struct {
-       long double x;
-       long double yf;
-       long double yi;
-} tl[] = {
-       0.7L, 0x1.6666666666666666p-1L, 0.0,
-       -0.7L, -0x1.6666666666666666p-1L, -0.0,
-       1.7L, 0x1.6666666666666668p-1L, 1.0,
-       -1.7L, -0x1.6666666666666668p-1L, -1.0,
-       2.0, 0, 2.0,
-       -2.0, -0.0, -2.0,
-       -0x1p99, -0.0, -0x1p99,
-       -0.0, -0.0, -0.0,
-       INFINITY, 0.0, INFINITY,
-       -INFINITY, -0.0, -INFINITY,
-       NAN, NAN, NAN,
-};
+       for (i = 0; i < sizeof t/sizeof *t; i++) {
+               p = t + i;
 
-#define eq(a, b) (isnan(a) && isnan(b) || ((a) == (b) && signbit(a) == signbit(b)))
+               if (p->r < 0)
+                       continue;
+               fesetround(p->r);
+               feclearexcept(FE_ALL_EXCEPT);
+               y = modf(p->x, &yi);
+               e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
 
-void test_modf()
-{
-       double yf, yi;
-       int i;
-       for (i = 0; i < sizeof t/sizeof *t; i++) {
-               yf = modf(t[i].x, &yi);
-               if (!eq(yf,t[i].yf) || !eq(yi,t[i].yi))
-                       error("modf(%a) want %a %a got %a %a\n", t[i].x, t[i].yf, t[i].yi, yf, yi);
-       }
-}
-void test_modff()
-{
-       float yf, yi;
-       int i;
-       for (i = 0; i < sizeof tf/sizeof *tf; i++) {
-               yf = modff(tf[i].x, &yi);
-               if (!eq(yf,tf[i].yf) || !eq(yi,tf[i].yi))
-                       error("modff(%a) want %a %a got %a %a\n", tf[i].x, tf[i].yf, tf[i].yi, yf, yi);
-       }
-}
-void test_modfl()
-{
-       long double yf, yi;
-       int i;
-       for (i = 0; i < sizeof tl/sizeof *tl; i++) {
-               yf = modfl(tl[i].x, &yi);
-               if (!eq(yf,tl[i].yf) || !eq(yi,tl[i].yi))
-                       error("modfl(%La) want %La %La got %La %La\n", tl[i].x, tl[i].yf, tl[i].yi, yf, yi);
+               /* TODO: fix inexact */
+               if (!checkexceptall(e|INEXACT, p->e|INEXACT, p->r)) {
+                       printf("%s:%d: bad fp exception: %s modf(%a)=%a,%a, want %s",
+                               p->file, p->line, rstr(p->r), p->x, p->y, p->y2, estr(p->e));
+                       printf(" got %s\n", estr(e));
+                       err++;
+               }
+               d = ulperr(y, p->y, p->dy);
+               di = ulperr(yi, p->y2, p->dy2);
+               if (!checkcr(y, p->y, p->r) || !checkcr(yi, p->y2, p->r)) {
+                       printf("%s:%d: %s modf(%a) want %a,%a got %a,%a, ulperr %.3f = %a + %a, %.3f = %a + %a\n",
+                               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);
+                       err++;
+               }
        }
+       return !!err;
 }