X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Fmodf.c;h=86be04f499aa139032eaa9065e5f8f38c9ed894d;hb=5729b0cb56800bde195ac79324f23af6a54bdaac;hp=43b8657933d2c64f2b443f170dbcff1cc9233f42;hpb=bed26db89037d70a6a422bb488ed08030a8e381b;p=libc-test diff --git a/src/math/modf.c b/src/math/modf.c index 43b8657..86be04f 100644 --- a/src/math/modf.c +++ b/src/math/modf.c @@ -1,90 +1,42 @@ +#include #include -#include -#include "test.h" +#include "util.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" }; -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); + 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; }