From 24541cca4d96f83eaf6a5b8223233ae669361908 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 26 Feb 2012 16:19:59 +0100 Subject: [PATCH] Refactor frexp*-ieee tests. * tests/test-frexp-ieee.h: New file. * tests/test-frexpf-ieee.c: Include test-frexp-ieee.h. (main): Just call test_function. * tests/test-frexp-ieee.c: Include test-frexp-ieee.h. (main): Just call test_function. * tests/test-frexpl-ieee.c: Include test-frexp-ieee.h. (main): Just call test_function. * modules/frexpf-ieee-tests (Files): Add tests/test-frexp-ieee.h. * modules/frexp-ieee-tests (Files): Likewise. * modules/frexpl-ieee-tests (Files): Likewise. --- ChangeLog | 12 ++++++++++ modules/frexp-ieee-tests | 1 + modules/frexpf-ieee-tests | 1 + modules/frexpl-ieee-tests | 1 + tests/test-frexp-ieee.c | 54 ++++++++++------------------------------- tests/test-frexp-ieee.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++ tests/test-frexpf-ieee.c | 54 ++++++++++------------------------------- tests/test-frexpl-ieee.c | 54 ++++++++++------------------------------- 8 files changed, 115 insertions(+), 123 deletions(-) create mode 100644 tests/test-frexp-ieee.h diff --git a/ChangeLog b/ChangeLog index f08dfd8f5..cb19d9f55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2012-02-26 Bruno Haible + Refactor frexp*-ieee tests. + * tests/test-frexp-ieee.h: New file. + * tests/test-frexpf-ieee.c: Include test-frexp-ieee.h. + (main): Just call test_function. + * tests/test-frexp-ieee.c: Include test-frexp-ieee.h. + (main): Just call test_function. + * tests/test-frexpl-ieee.c: Include test-frexp-ieee.h. + (main): Just call test_function. + * modules/frexpf-ieee-tests (Files): Add tests/test-frexp-ieee.h. + * modules/frexp-ieee-tests (Files): Likewise. + * modules/frexpl-ieee-tests (Files): Likewise. + Tests for module 'frexpl-ieee'. * modules/frexpl-ieee-tests: New file. * tests/test-frexpl-ieee.c: New file. diff --git a/modules/frexp-ieee-tests b/modules/frexp-ieee-tests index e3774f554..c055d525a 100644 --- a/modules/frexp-ieee-tests +++ b/modules/frexp-ieee-tests @@ -1,5 +1,6 @@ Files: tests/test-frexp-ieee.c +tests/test-frexp-ieee.h tests/minus-zero.h tests/infinity.h tests/nan.h diff --git a/modules/frexpf-ieee-tests b/modules/frexpf-ieee-tests index ca8d7eb72..19fb494a7 100644 --- a/modules/frexpf-ieee-tests +++ b/modules/frexpf-ieee-tests @@ -1,5 +1,6 @@ Files: tests/test-frexpf-ieee.c +tests/test-frexp-ieee.h tests/minus-zero.h tests/infinity.h tests/nan.h diff --git a/modules/frexpl-ieee-tests b/modules/frexpl-ieee-tests index 9e0fa399b..bd1968961 100644 --- a/modules/frexpl-ieee-tests +++ b/modules/frexpl-ieee-tests @@ -1,5 +1,6 @@ Files: tests/test-frexpl-ieee.c +tests/test-frexp-ieee.h tests/minus-zero.h tests/infinity.h tests/nan.h diff --git a/tests/test-frexp-ieee.c b/tests/test-frexp-ieee.c index 258d1dd66..72678e9e2 100644 --- a/tests/test-frexp-ieee.c +++ b/tests/test-frexp-ieee.c @@ -24,50 +24,22 @@ #include "nan.h" #include "macros.h" +#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 FREXP frexp +#include "test-frexp-ieee.h" + int main () { - /* [MX] shaded specification in POSIX. */ - - /* NaN. */ - { - int exp = -9999; - double mantissa; - mantissa = frexp (NaNd (), &exp); - ASSERT (isnand (mantissa)); - } - - /* Signed zero. */ - { - int exp = -9999; - double mantissa; - mantissa = frexp (0.0, &exp); - ASSERT (mantissa == 0.0); - ASSERT (!signbit (mantissa)); - ASSERT (exp == 0); - } - { - int exp = -9999; - double mantissa; - mantissa = frexp (minus_zerod, &exp); - ASSERT (mantissa == 0.0); - ASSERT (!!signbit (mantissa) == !!signbit (minus_zerod)); - ASSERT (exp == 0); - } - - /* Infinity. */ - { - int exp = -9999; - double mantissa; - mantissa = frexp (Infinityd (), &exp); - ASSERT (mantissa == Infinityd ()); - } - { - int exp = -9999; - double mantissa; - mantissa = frexp (- Infinityd (), &exp); - ASSERT (mantissa == - Infinityd ()); - } + test_function (); return 0; } diff --git a/tests/test-frexp-ieee.h b/tests/test-frexp-ieee.h new file mode 100644 index 000000000..83893b0c9 --- /dev/null +++ b/tests/test-frexp-ieee.h @@ -0,0 +1,61 @@ +/* Test of splitting a double into fraction and mantissa. + Copyright (C) 2012 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 . */ + +static void +test_function (void) +{ + /* [MX] shaded specification in POSIX. */ + + /* NaN. */ + { + int exp = -9999; + DOUBLE mantissa; + mantissa = FREXP (NAN, &exp); + ASSERT (ISNAN (mantissa)); + } + + /* Signed zero. */ + { + int exp = -9999; + DOUBLE mantissa; + mantissa = FREXP (L_(0.0), &exp); + ASSERT (mantissa == L_(0.0)); + ASSERT (!signbit (mantissa)); + ASSERT (exp == 0); + } + { + int exp = -9999; + DOUBLE mantissa; + mantissa = FREXP (MINUS_ZERO, &exp); + ASSERT (mantissa == L_(0.0)); + ASSERT (!!signbit (mantissa) == !!signbit (MINUS_ZERO)); + ASSERT (exp == 0); + } + + /* Infinity. */ + { + int exp = -9999; + DOUBLE mantissa; + mantissa = FREXP (INFINITY, &exp); + ASSERT (mantissa == INFINITY); + } + { + int exp = -9999; + DOUBLE mantissa; + mantissa = FREXP (- INFINITY, &exp); + ASSERT (mantissa == - INFINITY); + } +} diff --git a/tests/test-frexpf-ieee.c b/tests/test-frexpf-ieee.c index ea32ea9c2..cbecc1f0d 100644 --- a/tests/test-frexpf-ieee.c +++ b/tests/test-frexpf-ieee.c @@ -24,50 +24,22 @@ #include "nan.h" #include "macros.h" +#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 FREXP frexpf +#include "test-frexp-ieee.h" + int main () { - /* [MX] shaded specification in POSIX. */ - - /* NaN. */ - { - int exp = -9999; - float mantissa; - mantissa = frexpf (NaNf (), &exp); - ASSERT (isnanf (mantissa)); - } - - /* Signed zero. */ - { - int exp = -9999; - float mantissa; - mantissa = frexpf (0.0f, &exp); - ASSERT (mantissa == 0.0f); - ASSERT (!signbit (mantissa)); - ASSERT (exp == 0); - } - { - int exp = -9999; - float mantissa; - mantissa = frexpf (minus_zerof, &exp); - ASSERT (mantissa == 0.0f); - ASSERT (!!signbit (mantissa) == !!signbit (minus_zerof)); - ASSERT (exp == 0); - } - - /* Infinity. */ - { - int exp = -9999; - float mantissa; - mantissa = frexpf (Infinityf (), &exp); - ASSERT (mantissa == Infinityf ()); - } - { - int exp = -9999; - float mantissa; - mantissa = frexpf (- Infinityf (), &exp); - ASSERT (mantissa == - Infinityf ()); - } + test_function (); return 0; } diff --git a/tests/test-frexpl-ieee.c b/tests/test-frexpl-ieee.c index c9fae568a..1afc7e2e6 100644 --- a/tests/test-frexpl-ieee.c +++ b/tests/test-frexpl-ieee.c @@ -24,50 +24,22 @@ #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 FREXP frexpl +#include "test-frexp-ieee.h" + int main () { - /* [MX] shaded specification in POSIX. */ - - /* NaN. */ - { - int exp = -9999; - long double mantissa; - mantissa = frexpl (NaNl (), &exp); - ASSERT (isnanl (mantissa)); - } - - /* Signed zero. */ - { - int exp = -9999; - long double mantissa; - mantissa = frexpl (0.0L, &exp); - ASSERT (mantissa == 0.0L); - ASSERT (!signbit (mantissa)); - ASSERT (exp == 0); - } - { - int exp = -9999; - long double mantissa; - mantissa = frexpl (minus_zerol, &exp); - ASSERT (mantissa == 0.0L); - ASSERT (!!signbit (mantissa) == !!signbit (minus_zerol)); - ASSERT (exp == 0); - } - - /* Infinity. */ - { - int exp = -9999; - long double mantissa; - mantissa = frexpl (Infinityl (), &exp); - ASSERT (mantissa == Infinityl ()); - } - { - int exp = -9999; - long double mantissa; - mantissa = frexpl (- Infinityl (), &exp); - ASSERT (mantissa == - Infinityl ()); - } + test_function (); return 0; } -- 2.11.0