From: Bruno Haible Date: Sun, 6 Nov 2011 12:52:30 +0000 (+0100) Subject: ldexp, ldexpf, ldexpl: Enhance tests. X-Git-Tag: v0.1~1480 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=dc57f70a80411608fee719971cc758a00a8eab63;p=gnulib.git ldexp, ldexpf, ldexpl: Enhance tests. * tests/test-ldexp.h: New file, combining code from tests/test-ldexp.c and tests/test-ldexpl.c. * tests/test-ldexpl.c: (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, MAX_EXP): New macros. Include test-ldexp.h. (main): Just call test_function. * tests/test-ldexp.c: Include float.h, isnand-nolibm.h, minus-zero.h, infinity.h, nan.h. (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, MAX_EXP): New macros. Include test-ldexp.h. (x, y): Remove variables. (main): Just call test_function. * tests/test-ldexpf.c: Include float.h, isnanf-nolibm.h, minus-zero.h, infinity.h, nan.h. (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, MAX_EXP): New macros. Include test-ldexp.h. (x, y): Remove variables. (main): Just call test_function. * modules/ldexpl-tests (Files): Add tests/test-ldexp.h. * modules/ldexp-tests (Files): Add tests/test-ldexp.h, tests/minus-zero.h, tests/infinity.h, tests/nan.h. (Depends-on): Add isnand-nolibm, signbit, float. * modules/ldexpf-tests (Files): Add tests/test-ldexp.h, tests/minus-zero.h, tests/infinity.h, tests/nan.h. (Depends-on): Add isnanf-nolibm, signbit, float. --- diff --git a/ChangeLog b/ChangeLog index eabe04a05..2a12bf74e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,36 @@ 2011-11-06 Bruno Haible + ldexp, ldexpf, ldexpl: Enhance tests. + * tests/test-ldexp.h: New file, combining code from tests/test-ldexp.c + and tests/test-ldexpl.c. + * tests/test-ldexpl.c: (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, + LDEXP, MIN_EXP, MAX_EXP): New macros. + Include test-ldexp.h. + (main): Just call test_function. + * tests/test-ldexp.c: Include float.h, isnand-nolibm.h, minus-zero.h, + infinity.h, nan.h. + (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, + MAX_EXP): New macros. + Include test-ldexp.h. + (x, y): Remove variables. + (main): Just call test_function. + * tests/test-ldexpf.c: Include float.h, isnanf-nolibm.h, minus-zero.h, + infinity.h, nan.h. + (DOUBLE, ISNAN, INFINITY, NAN, L_, MINUS_ZERO, LDEXP, MIN_EXP, + MAX_EXP): New macros. + Include test-ldexp.h. + (x, y): Remove variables. + (main): Just call test_function. + * modules/ldexpl-tests (Files): Add tests/test-ldexp.h. + * modules/ldexp-tests (Files): Add tests/test-ldexp.h, + tests/minus-zero.h, tests/infinity.h, tests/nan.h. + (Depends-on): Add isnand-nolibm, signbit, float. + * modules/ldexpf-tests (Files): Add tests/test-ldexp.h, + tests/minus-zero.h, tests/infinity.h, tests/nan.h. + (Depends-on): Add isnanf-nolibm, signbit, float. + +2011-11-06 Bruno Haible + math tests: Cosmetics. * tests/test-math-c++.cc: Reorder declarations. diff --git a/modules/ldexp-tests b/modules/ldexp-tests index e5d796cb1..bd252cf50 100644 --- a/modules/ldexp-tests +++ b/modules/ldexp-tests @@ -1,9 +1,16 @@ Files: tests/test-ldexp.c +tests/test-ldexp.h +tests/minus-zero.h +tests/infinity.h +tests/nan.h tests/signature.h tests/macros.h Depends-on: +isnand-nolibm +signbit +float configure.ac: diff --git a/modules/ldexpf-tests b/modules/ldexpf-tests index 1c387f120..5de320343 100644 --- a/modules/ldexpf-tests +++ b/modules/ldexpf-tests @@ -1,9 +1,16 @@ Files: tests/test-ldexpf.c +tests/test-ldexp.h +tests/minus-zero.h +tests/infinity.h +tests/nan.h tests/signature.h tests/macros.h Depends-on: +isnanf-nolibm +signbit +float configure.ac: diff --git a/modules/ldexpl-tests b/modules/ldexpl-tests index 2fa043438..828143e44 100644 --- a/modules/ldexpl-tests +++ b/modules/ldexpl-tests @@ -1,5 +1,6 @@ Files: tests/test-ldexpl.c +tests/test-ldexp.h tests/minus-zero.h tests/infinity.h tests/nan.h diff --git a/tests/test-ldexp.c b/tests/test-ldexp.c index 9eb6e5e32..ea8a9cc2d 100644 --- a/tests/test-ldexp.c +++ b/tests/test-ldexp.c @@ -1,5 +1,5 @@ /* Test of ldexp() function. - Copyright (C) 2010-2011 Free Software Foundation, Inc. + Copyright (C) 2007-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* Written by Bruno Haible , 2010. */ +/* Written by Bruno Haible , 2007, 2010. */ #include @@ -23,26 +23,32 @@ #include "signature.h" SIGNATURE_CHECK (ldexp, double, (double, int)); +#include + +#include "isnand-nolibm.h" +#include "minus-zero.h" +#include "infinity.h" +#include "nan.h" #include "macros.h" -volatile double x; -double y; +#undef INFINITY +#undef NAN + +#define DOUBLE double +#define ISNAN isnand +#define INFINITY Infinityd () +#define NAN NaNd () +#define L_(literal) literal +#define MINUS_ZERO minus_zerod +#define LDEXP ldexp +#define MIN_EXP DBL_MIN_EXP +#define MAX_EXP DBL_MAX_EXP +#include "test-ldexp.h" int main () { - /* A particular value. */ - x = 0.6; - y = ldexp (x, 0); - ASSERT (y >= 0.5999999999 && y <= 0.6000000001); - - x = 0.6; - y = ldexp (x, 1); - ASSERT (y >= 1.199999999 && y <= 1.200000001); - - x = 0.6; - y = ldexp (x, -1); - ASSERT (y >= 0.2999999999 && y <= 0.3000000001); + test_function (); return 0; } diff --git a/tests/test-ldexp.h b/tests/test-ldexp.h new file mode 100644 index 000000000..260f54c8d --- /dev/null +++ b/tests/test-ldexp.h @@ -0,0 +1,117 @@ +/* Test of ldexp*() function family. + Copyright (C) 2007-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2007, 2010. */ + +static void +test_function (void) +{ + int i; + volatile DOUBLE x; + volatile DOUBLE y; + + /* A particular value. */ + { + x = L_(0.6); + y = LDEXP (x, 0); + ASSERT (y >= L_(0.5999999999) && y <= L_(0.6000000001)); + } + { + x = L_(0.6); + y = LDEXP (x, 1); + ASSERT (y >= L_(1.199999999) && y <= L_(1.200000001)); + } + { + x = L_(0.6); + y = LDEXP (x, -1); + ASSERT (y >= L_(0.2999999999) && y <= L_(0.3000000001)); + } + + { /* NaN. */ + x = NAN; + y = LDEXP (x, 0); ASSERT (ISNAN (y)); + y = LDEXP (x, 5); ASSERT (ISNAN (y)); + y = LDEXP (x, -5); ASSERT (ISNAN (y)); + } + + { /* Positive infinity. */ + x = INFINITY; + y = LDEXP (x, 0); ASSERT (y == x); + y = LDEXP (x, 5); ASSERT (y == x); + y = LDEXP (x, -5); ASSERT (y == x); + } + + { /* Negative infinity. */ + x = - INFINITY; + y = LDEXP (x, 0); ASSERT (y == x); + y = LDEXP (x, 5); ASSERT (y == x); + y = LDEXP (x, -5); ASSERT (y == x); + } + + { /* Positive zero. */ + x = L_(0.0); + y = LDEXP (x, 0); ASSERT (y == x); ASSERT (!signbit (x)); + y = LDEXP (x, 5); ASSERT (y == x); ASSERT (!signbit (x)); + y = LDEXP (x, -5); ASSERT (y == x); ASSERT (!signbit (x)); + } + + { /* Negative zero. */ + x = MINUS_ZERO; + y = LDEXP (x, 0); ASSERT (y == x); ASSERT (signbit (x)); + y = LDEXP (x, 5); ASSERT (y == x); ASSERT (signbit (x)); + y = LDEXP (x, -5); ASSERT (y == x); ASSERT (signbit (x)); + } + + { /* Positive finite number. */ + x = L_(1.73205); + y = LDEXP (x, 0); ASSERT (y == x); + y = LDEXP (x, 5); ASSERT (y == x * L_(32.0)); + y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125)); + } + + { /* Negative finite number. */ + x = - L_(20.085536923187667742); + y = LDEXP (x, 0); ASSERT (y == x); + y = LDEXP (x, 5); ASSERT (y == x * L_(32.0)); + y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125)); + } + + for (i = 1, x = L_(1.73205); i <= MAX_EXP; i++, x *= L_(2.0)) + { + y = LDEXP (x, 0); ASSERT (y == x); + { + volatile DOUBLE expected; + y = LDEXP (x, 5); + expected = x * L_(32.0); + ASSERT (y == expected); + } + y = LDEXP (x, -5); ASSERT (y == x * 0.03125L); + } + for (i = 1, x = L_(1.73205); i >= MIN_EXP; i--, x *= L_(0.5)) + { + y = LDEXP (x, 0); ASSERT (y == x); + y = LDEXP (x, 5); ASSERT (y == x * L_(32.0)); + if (i - 5 >= MIN_EXP) + { + y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125)); + } + } + for (; i >= LDBL_MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5)) + { + y = LDEXP (x, 0); ASSERT (y == x); + y = LDEXP (x, 5); ASSERT (y == x * L_(32.0)); + } +} diff --git a/tests/test-ldexpf.c b/tests/test-ldexpf.c index 12fc4d22f..e90c13d60 100644 --- a/tests/test-ldexpf.c +++ b/tests/test-ldexpf.c @@ -1,5 +1,5 @@ /* Test of ldexpf() function. - Copyright (C) 2010-2011 Free Software Foundation, Inc. + Copyright (C) 2007-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* Written by Bruno Haible , 2010. */ +/* Written by Bruno Haible , 2007, 2010. */ #include @@ -23,26 +23,32 @@ #include "signature.h" SIGNATURE_CHECK (ldexpf, float, (float, int)); +#include + +#include "isnanf-nolibm.h" +#include "minus-zero.h" +#include "infinity.h" +#include "nan.h" #include "macros.h" -volatile float x; -float y; +#undef INFINITY +#undef NAN + +#define DOUBLE float +#define ISNAN isnanf +#define INFINITY Infinityf () +#define NAN NaNf () +#define L_(literal) literal##f +#define MINUS_ZERO minus_zerof +#define LDEXP ldexpf +#define MIN_EXP FLT_MIN_EXP +#define MAX_EXP FLT_MAX_EXP +#include "test-ldexp.h" int main () { - /* A particular value. */ - x = 0.6f; - y = ldexp (x, 0); - ASSERT (y >= 0.59999999f && y <= 0.60000001f); - - x = 0.6f; - y = ldexp (x, 1); - ASSERT (y >= 1.1999999f && y <= 1.2000001f); - - x = 0.6f; - y = ldexp (x, -1); - ASSERT (y >= 0.29999999f && y <= 0.30000001f); + test_function (); return 0; } diff --git a/tests/test-ldexpl.c b/tests/test-ldexpl.c index e78e9a5d8..5dd9b4a90 100644 --- a/tests/test-ldexpl.c +++ b/tests/test-ldexpl.c @@ -32,90 +32,28 @@ SIGNATURE_CHECK (ldexpl, long double, (long double, int)); #include "nan.h" #include "macros.h" +#undef INFINITY +#undef NAN + +#define DOUBLE long double +#define ISNAN isnanl +#define INFINITY Infinityl () +#define NAN NaNl () +#define L_(literal) literal##L +#define MINUS_ZERO minus_zerol +#define LDEXP ldexpl +#define MIN_EXP LDBL_MIN_EXP +#define MAX_EXP LDBL_MAX_EXP +#include "test-ldexp.h" + int main () { - int i; - long double x; - long double y; DECL_LONG_DOUBLE_ROUNDING BEGIN_LONG_DOUBLE_ROUNDING (); - { /* NaN. */ - x = NaNl (); - y = ldexpl (x, 0); ASSERT (isnanl (y)); - y = ldexpl (x, 5); ASSERT (isnanl (y)); - y = ldexpl (x, -5); ASSERT (isnanl (y)); - } - - { /* Positive infinity. */ - x = Infinityl (); - y = ldexpl (x, 0); ASSERT (y == x); - y = ldexpl (x, 5); ASSERT (y == x); - y = ldexpl (x, -5); ASSERT (y == x); - } - - { /* Negative infinity. */ - x = - Infinityl (); - y = ldexpl (x, 0); ASSERT (y == x); - y = ldexpl (x, 5); ASSERT (y == x); - y = ldexpl (x, -5); ASSERT (y == x); - } - - { /* Positive zero. */ - x = 0.0L; - y = ldexpl (x, 0); ASSERT (y == x); ASSERT (!signbit (x)); - y = ldexpl (x, 5); ASSERT (y == x); ASSERT (!signbit (x)); - y = ldexpl (x, -5); ASSERT (y == x); ASSERT (!signbit (x)); - } - - { /* Negative zero. */ - x = minus_zerol; - y = ldexpl (x, 0); ASSERT (y == x); ASSERT (signbit (x)); - y = ldexpl (x, 5); ASSERT (y == x); ASSERT (signbit (x)); - y = ldexpl (x, -5); ASSERT (y == x); ASSERT (signbit (x)); - } - - { /* Positive finite number. */ - x = 1.73205L; - y = ldexpl (x, 0); ASSERT (y == x); - y = ldexpl (x, 5); ASSERT (y == x * 32.0L); - y = ldexpl (x, -5); ASSERT (y == x * 0.03125L); - } - - { /* Negative finite number. */ - x = -20.085536923187667742L; - y = ldexpl (x, 0); ASSERT (y == x); - y = ldexpl (x, 5); ASSERT (y == x * 32.0L); - y = ldexpl (x, -5); ASSERT (y == x * 0.03125L); - } - - for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L) - { - y = ldexpl (x, 0); ASSERT (y == x); - { - volatile long double expected; - y = ldexpl (x, 5); - expected = x * 32.0L; - ASSERT (y == expected); - } - y = ldexpl (x, -5); ASSERT (y == x * 0.03125L); - } - for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L) - { - y = ldexpl (x, 0); ASSERT (y == x); - y = ldexpl (x, 5); ASSERT (y == x * 32.0L); - if (i - 5 >= LDBL_MIN_EXP) - { - y = ldexpl (x, -5); ASSERT (y == x * 0.03125L); - } - } - for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L) - { - y = ldexpl (x, 0); ASSERT (y == x); - y = ldexpl (x, 5); ASSERT (y == x * 32.0L); - } + test_function (); return 0; }