X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Ffenv.c;h=960350443baaad083358cf2f9e0608bc58241e3e;hb=705b5a4d2d3b6eeb14b201c097252c5918995d98;hp=e15f0bc07758388993ad07a07f20a43b3e33dd27;hpb=4b4849e54740efe153632dfb14052d7210cea6c6;p=libc-test diff --git a/src/math/fenv.c b/src/math/fenv.c index e15f0bc..9603504 100644 --- a/src/math/fenv.c +++ b/src/math/fenv.c @@ -37,6 +37,7 @@ static struct { #ifdef FE_UNDERFLOW F(FE_UNDERFLOW), #endif + {0, 0} }; static void test_except() @@ -45,7 +46,7 @@ static void test_except() int i,r; fenv_t env; - for (i=0; i < sizeof te/sizeof*te; i++) { + for (i=0; te[i].i; i++) { feclearexcept(FE_ALL_EXCEPT); r = feraiseexcept(te[i].i); @@ -57,10 +58,15 @@ static void test_except() te[i].name, te[i].i, r); } + r = feraiseexcept(FE_ALL_EXCEPT); + if (r != 0) + error("feraisexcept(FE_ALL_EXCEPT) failed\n"); r = fegetenv(&env); if (r != 0) error("fegetenv(&env) = %d\n", r); - i = fetestexcept(FE_ALL_EXCEPT); + r = fetestexcept(FE_ALL_EXCEPT); + if (r != FE_ALL_EXCEPT) + error("fetestexcept failed: got 0x%x, want 0x%x (FE_ALL_ECXEPT)\n", r, FE_ALL_EXCEPT); r = fesetenv(FE_DFL_ENV); if (r != 0) error("fesetenv(FE_DFL_ENV) = %d\n", r); @@ -71,7 +77,7 @@ static void test_except() if (r != 0) error("fesetenv(&env) = %d\n", r); r = fetestexcept(FE_ALL_EXCEPT); - if (r != i) + if (r != FE_ALL_EXCEPT) error("fesetenv(&env) did not restore exceptions: 0x%x\n", r); } @@ -200,10 +206,42 @@ static void test_round_add(void) } } +static void test_bad(void) +{ + fexcept_t f; + int r; + + r = feclearexcept(FE_ALL_EXCEPT); + if (r != 0) + error("feclearexcept(FE_ALL_EXCEPT) failed\n"); + r = fetestexcept(-1); + if (r != 0) + error("fetestexcept(-1) should return 0 when all exceptions are cleared, got %d\n", r); + r = feraiseexcept(1234567|FE_ALL_EXCEPT); + if (r != 0) + error("feraiseexcept returned non-zero for non-supported exceptions: %d\n", r); + r = feclearexcept(1234567|FE_ALL_EXCEPT); + if (r != 0) + error("feclearexcept returned non-zero for non-supported exceptions: %d\n", r); + r = fesetround(1234567); + if (r == 0) + error("fesetround should fail on invalid rounding mode\n"); + r = fegetexceptflag(&f, 1234567); + if (r != 0) + error("fegetexceptflag returned non-zero for non-supported exceptions: %d\n", r); + r = fegetexceptflag(&f, 0); + if (r != 0) + error("fegetexceptflag(0) failed\n"); + r = fesetexceptflag(&f, 1234567); + if (r != 0) + error("fesetexceptflag returned non-zero fir non-supported exceptions: %d\n", r); +} + int main(void) { test_except(); test_round(); test_round_add(); + test_bad(); return test_status; }