From 5c5a96225e9f7e01aa6ec92dd26228eb6996f77f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 4 Mar 2012 20:59:05 +0100 Subject: [PATCH] fmod* tests: More tests. * tests/test-fmod.h (my_ldexp): New function. (test_function): Reduce amount of random numbers to test. Add tests of very large quotients x / y. * tests/test-fmod.c (MAX_EXP): New macro. * tests/test-fmodf.c (MAX_EXP): Likewise. * tests/test-fmodl.c (MAX_EXP): Likewise. --- ChangeLog | 10 ++++++++++ tests/test-fmod.c | 1 + tests/test-fmod.h | 37 +++++++++++++++++++++++++++++++++---- tests/test-fmodf.c | 1 + tests/test-fmodl.c | 1 + 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c55974ff01..f840f5c513 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-03-04 Bruno Haible + + fmod* tests: More tests. + * tests/test-fmod.h (my_ldexp): New function. + (test_function): Reduce amount of random numbers to test. Add tests + of very large quotients x / y. + * tests/test-fmod.c (MAX_EXP): New macro. + * tests/test-fmodf.c (MAX_EXP): Likewise. + * tests/test-fmodl.c (MAX_EXP): Likewise. + 2012-03-04 Bruno Haible fmod, fmodl: Fix computation for large quotients x / y. diff --git a/tests/test-fmod.c b/tests/test-fmod.c index 27a23e3026..36799f165d 100644 --- a/tests/test-fmod.c +++ b/tests/test-fmod.c @@ -30,6 +30,7 @@ SIGNATURE_CHECK (fmod, double, (double, double)); #define DOUBLE double #define L_(literal) literal #define MANT_DIG DBL_MANT_DIG +#define MAX_EXP DBL_MAX_EXP #define FMOD fmod #define RANDOM randomd #include "test-fmod.h" diff --git a/tests/test-fmod.h b/tests/test-fmod.h index 3092860d31..a513857378 100644 --- a/tests/test-fmod.h +++ b/tests/test-fmod.h @@ -14,6 +14,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +static DOUBLE +my_ldexp (DOUBLE x, int d) +{ + for (; d > 0; d--) + x *= L_(2.0); + for (; d < 0; d++) + x *= L_(0.5); + return x; +} + static void test_function (void) { @@ -30,8 +40,8 @@ test_function (void) * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5)); /* Randomized tests. */ - for (i = 0; i < SIZEOF (RANDOM); i++) - for (j = 0; j < SIZEOF (RANDOM); j++) + for (i = 0; i < SIZEOF (RANDOM) / 5; i++) + for (j = 0; j < SIZEOF (RANDOM) / 5; j++) { DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */ DOUBLE y = RANDOM[j]; /* 0.0 <= y < 1.0 */ @@ -53,8 +63,8 @@ test_function (void) } } - for (i = 0; i < SIZEOF (RANDOM); i++) - for (j = 0; j < SIZEOF (RANDOM); j++) + for (i = 0; i < SIZEOF (RANDOM) / 5; i++) + for (j = 0; j < SIZEOF (RANDOM) / 5; j++) { DOUBLE x = L_(1.0e9) * RANDOM[i]; /* 0.0 <= x <= 10^9 */ DOUBLE y = RANDOM[j]; /* 0.0 <= y < 1.0 */ @@ -87,6 +97,25 @@ test_function (void) && z < - y + L_(2.0) * L_(1.0e9) / TWO_MANT_DIG)); } } + + { + int large_exp = (MAX_EXP - 1 < 1000 ? MAX_EXP - 1 : 1000); + DOUBLE large = my_ldexp (L_(1.0), large_exp); /* = 2^large_exp */ + for (i = 0; i < SIZEOF (RANDOM) / 10; i++) + for (j = 0; j < SIZEOF (RANDOM) / 10; j++) + { + DOUBLE x = large * RANDOM[i]; /* 0.0 <= x <= 2^large_exp */ + DOUBLE y = RANDOM[j]; /* 0.0 <= y < 1.0 */ + if (y > L_(0.0)) + { + DOUBLE z = FMOD (x, y); + /* Regardless how large the rounding errors are, the result + must be >= 0, < y. */ + ASSERT (z >= L_(0.0)); + ASSERT (z < y); + } + } + } } volatile DOUBLE x; diff --git a/tests/test-fmodf.c b/tests/test-fmodf.c index fcb830bbd9..f968b09054 100644 --- a/tests/test-fmodf.c +++ b/tests/test-fmodf.c @@ -30,6 +30,7 @@ SIGNATURE_CHECK (fmodf, float, (float, float)); #define DOUBLE float #define L_(literal) literal##f #define MANT_DIG FLT_MANT_DIG +#define MAX_EXP FLT_MAX_EXP #define FMOD fmodf #define RANDOM randomf #include "test-fmod.h" diff --git a/tests/test-fmodl.c b/tests/test-fmodl.c index 53054d1343..95a38b8ce1 100644 --- a/tests/test-fmodl.c +++ b/tests/test-fmodl.c @@ -31,6 +31,7 @@ SIGNATURE_CHECK (fmodl, long double, (long double, long double)); #define DOUBLE long double #define L_(literal) literal##L #define MANT_DIG LDBL_MANT_DIG +#define MAX_EXP LDBL_MAX_EXP #define FMOD fmodl #define RANDOM randoml #include "test-fmod.h" -- 2.39.5