# HG changeset patch # User Bruno Haible # Date 1330338941 -3600 # Node ID dea6693446faddbded89452b36e626013bf171e0 # Parent ba1e81c9042b2f4cf34900335dcdc42163be29d9 fmodl-ieee: Fix test failures. * lib/fmodl.c (fmodl): Treat Inf specially. * modules/fmodl (Depends-on): Add isinf. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-02-27 Bruno Haible + fmodl-ieee: Fix test failures. + * lib/fmodl.c (fmodl): Treat Inf specially. + * modules/fmodl (Depends-on): Add isinf. + Tests for module 'fmodl-ieee'. * modules/fmodl-ieee-tests: New file. * tests/test-fmodl-ieee.c: New file. diff --git a/lib/fmodl.c b/lib/fmodl.c --- a/lib/fmodl.c +++ b/lib/fmodl.c @@ -32,48 +32,53 @@ long double fmodl (long double x, long double y) { - long double q = - truncl (x / y); - long double r = fmal (q, y, x); /* = x + q * y, computed in one step */ - /* Correct possible rounding errors in the quotient x / y. */ - if (y >= 0) + if (isinf (y)) + return x; + else { - if (x >= 0) + long double q = - truncl (x / y); + long double r = fmal (q, y, x); /* = x + q * y, computed in one step */ + /* Correct possible rounding errors in the quotient x / y. */ + if (y >= 0) { - /* Expect 0 <= r < y. */ - if (r < 0) - q += 1, r = fmal (q, y, x); - else if (r >= y) - q -= 1, r = fmal (q, y, x); + if (x >= 0) + { + /* Expect 0 <= r < y. */ + if (r < 0) + q += 1, r = fmal (q, y, x); + else if (r >= y) + q -= 1, r = fmal (q, y, x); + } + else + { + /* Expect - y < r <= 0. */ + if (r > 0) + q -= 1, r = fmal (q, y, x); + else if (r <= - y) + q += 1, r = fmal (q, y, x); + } } else { - /* Expect - y < r <= 0. */ - if (r > 0) - q -= 1, r = fmal (q, y, x); - else if (r <= - y) - q += 1, r = fmal (q, y, x); + if (x >= 0) + { + /* Expect 0 <= r < - y. */ + if (r < 0) + q -= 1, r = fmal (q, y, x); + else if (r >= - y) + q += 1, r = fmal (q, y, x); + } + else + { + /* Expect y < r <= 0. */ + if (r > 0) + q += 1, r = fmal (q, y, x); + else if (r <= y) + q -= 1, r = fmal (q, y, x); + } } + return r; } - else - { - if (x >= 0) - { - /* Expect 0 <= r < - y. */ - if (r < 0) - q -= 1, r = fmal (q, y, x); - else if (r >= - y) - q += 1, r = fmal (q, y, x); - } - else - { - /* Expect y < r <= 0. */ - if (r > 0) - q += 1, r = fmal (q, y, x); - else if (r <= y) - q -= 1, r = fmal (q, y, x); - } - } - return r; } #endif diff --git a/modules/fmodl b/modules/fmodl --- a/modules/fmodl +++ b/modules/fmodl @@ -9,6 +9,7 @@ Depends-on: math fmod [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +isinf [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] truncl [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] fmal [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]