From: Bruno Haible Date: Mon, 27 Feb 2012 10:35:41 +0000 (+0100) Subject: fmodl-ieee: Fix test failures. X-Git-Tag: v0.1~1041 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=9e83e486f6e0949ad5d3843011ae88c495681727;p=gnulib.git fmodl-ieee: Fix test failures. * lib/fmodl.c (fmodl): Treat Inf specially. * modules/fmodl (Depends-on): Add isinf. --- diff --git a/ChangeLog b/ChangeLog index dc0b33b988..37d52ed1a4 100644 --- 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 index a7ccd8bcd5..8ddd62bad2 100644 --- a/lib/fmodl.c +++ b/lib/fmodl.c @@ -32,48 +32,53 @@ fmodl (long double x, long double y) 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 (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); - } - } + 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; } - return r; } #endif diff --git a/modules/fmodl b/modules/fmodl index 29b5843bc9..bf192ee97d 100644 --- a/modules/fmodl +++ b/modules/fmodl @@ -9,6 +9,7 @@ m4/mathfunc.m4 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]