math: add modf and sincos
[libc-test] / src / math / modf.c
diff --git a/src/math/modf.c b/src/math/modf.c
new file mode 100644 (file)
index 0000000..86be04f
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdint.h>
+#include <stdio.h>
+#include "util.h"
+
+static struct d_dd t[] = {
+#include "sanity/modf.h"
+};
+
+int main(void)
+{
+       #pragma STDC FENV_ACCESS ON
+       double y, yi;
+       float d, di;
+       int e, i, err = 0;
+       struct d_dd *p;
+
+       for (i = 0; i < sizeof t/sizeof *t; i++) {
+               p = t + i;
+
+               if (p->r < 0)
+                       continue;
+               fesetround(p->r);
+               feclearexcept(FE_ALL_EXCEPT);
+               y = modf(p->x, &yi);
+               e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
+
+               if (!checkexcept(e, p->e, 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 (!checkulp(d, p->r) || !checkulp(di, 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;
+}