math: fix nexttoward*
[libc-test] / src / math / scalbn.c
index b4a56be..99fdc1b 100644 (file)
@@ -1,72 +1,42 @@
-#include "test.h"
-#include <math.h>
 #include <stdint.h>
-#include <fenv.h>
 #include <stdio.h>
-#include <float.h>
+#include "util.h"
+
+static struct di_d t[] = {
+#include "sanity/scalbn.h"
 
-static struct {
-       double x;
-       int n;
-       double y;
-} t[] = {
-       0.0, 0, 0.0,
-       -0.0, 0, -0.0,
-       0.0, -1234567, 0.0,
-       -0.0, 1234567, -0.0,
-       0x1.234p0, 13, 0x1.234p13,
-       0x1.234p0, -13, 0x1.234p-13,
-       -0x1.234p1, 137, -0x1.234p138,
-       -0x1.234p1, -137, -0x1.234p-136,
-       0x1.234p1023, 1, INFINITY,
-       0x1.234p1023, -1022, 0x1.234p1,
-       0x1.234p1023, -1023, 0x1.234p0,
-       0x1.234p1023, -1024, 0x1.234p-1,
-       0x1.234p1023, -2023, 0x1.234p-1000,
-       0x1.234p1023, -2045, 0x1.234p-1022,
-       0x1.234p1023, -2046, 0x1.234p-1023,
-       0x1.234p1023, -2048, 0x1.234p-1025,
-       0x1.234p1023, -2049, 0x1.234p-1026,
-       0x1p1023, -2096, 0x1p-1073,
-       0x1p1023, -2097, 0x1p-1074,
-       0x1p1023, -2098, 0,
-       0x1.234p-1022, 1022, 0x1.234p0,
-       0x1.234p-1022, 2045, 0x1.234p1023,
-       0x1p-1074, 2097, 0x1p1023,
-       0x1p-1074, 2098, INFINITY,
-       0x1p-1074, 1, 0x1p-1073,
-       0x1p-1073, -1, 0x1p-1074,
-       0x1p-1074, -1, 0,
 };
 
-void test_scalbn()
+int main(void)
 {
-       int i;
+       #pragma STDC FENV_ACCESS ON
        double y;
+       float d;
+       int e, i, err = 0;
+       struct di_d *p;
 
        for (i = 0; i < sizeof t/sizeof *t; i++) {
-               y = scalbn(t[i].x, t[i].n);
-               if (y != t[i].y)
-                       error("scalbn(%a,%d) want %a got %a\n", t[i].x, t[i].n, t[i].y, y);
-       }
-}
-
-void bench_scalbn_simple(int N)
-{
-       int i;
-       volatile double y;
+               p = t + i;
 
-       for (i = 0; i < N; i++) {
-               y = scalbn(1.25, 73);
-       }
-}
-
-void bench_scalbn_hard(int N)
-{
-       int i;
-       volatile double y;
+               if (p->r < 0)
+                       continue;
+               fesetround(p->r);
+               feclearexcept(FE_ALL_EXCEPT);
+               y = scalbn(p->x, p->i);
+               e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
 
-       for (i = 0; i < N; i++) {
-               y = scalbn(0x1.23p-1050, 2070);
+               if (!checkexcept(e, p->e, p->r)) {
+                       printf("%s:%d: bad fp exception: %s scalbn(%a, %lld)=%a, want %s",
+                               p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e));
+                       printf(" got %s\n", estr(e));
+                       err++;
+               }
+               d = ulperr(y, p->y, p->dy);
+               if (!checkulp(d, p->r)) {
+                       printf("%s:%d: %s scalbn(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n",
+                               p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy);
+                       err++;
+               }
        }
+       return !!err;
 }