add math/modf.c test
authornsz <nsz@port70.net>
Wed, 28 Mar 2012 23:19:01 +0000 (01:19 +0200)
committernsz <nsz@port70.net>
Wed, 28 Mar 2012 23:19:01 +0000 (01:19 +0200)
src/math/modf.c [new file with mode: 0644]

diff --git a/src/math/modf.c b/src/math/modf.c
new file mode 100644 (file)
index 0000000..43b8657
--- /dev/null
@@ -0,0 +1,90 @@
+#include <stdio.h>
+#include <math.h>
+#include "test.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 {
+       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,
+};
+
+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,
+};
+
+#define eq(a, b) (isnan(a) && isnan(b) || ((a) == (b) && signbit(a) == signbit(b)))
+
+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);
+       }
+}