X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Fmodf.c;h=c0ce9d894073f222fd0709f3a9631da1cb2c0864;hb=4f18b8f0b3cf4a59aea5258adcdd32ba2a0b6741;hp=8a5cc957a1aacf74908153a4a28f26de97db6593;hpb=ef368907f19f951b188f0940b8b42cf6efc696bf;p=libc-test diff --git a/src/math/modf.c b/src/math/modf.c index 8a5cc95..c0ce9d8 100644 --- a/src/math/modf.c +++ b/src/math/modf.c @@ -1,108 +1,43 @@ +#include #include -#include -#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, -}; - -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() +int main(void) { - double yf, yi; - int i; + #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++) { - 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); + 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 (!checkexceptall(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 (!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++; + } } -} - -void bench_modf_small(int N) -{ - int i; - volatile double yf, yi; - - for (i = 0; i < N; i++) - yf = modf(1234.5678, &yi); -} - -void bench_modf_large(int N) -{ - int i; - volatile double yf, yi; - - for (i = 0; i < N; i++) - yf = modf(1.2345678e300, &yi); + return !!err; }