From: Bruno Haible Date: Sat, 10 Mar 2012 09:56:05 +0000 (+0100) Subject: log* tests: More tests. X-Git-Tag: v0.1~892 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=7e105c7957aab59bbf060758c2b3e285feaea229;p=gnulib.git log* tests: More tests. * tests/test-log.h: New file. * tests/test-log.c: Include , minus-zero.h, test-log.h. (main): Invoke test_function. * tests/test-logf.c: Include , minus-zero.h, test-log.h. (main): Invoke test_function. * tests/test-logl.c: Include , minus-zero.h, test-log.h. (main): Invoke test_function. * modules/log-tests (Files): Add tests/test-log.h, tests/minus-zero.h, tests/randomd.c. (Makefile.am): Add randomd.c to test_log_SOURCES. * modules/logf-tests (Files): Add tests/test-log.h, tests/minus-zero.h, tests/randomf.c. (Makefile.am): Add randomf.c to test_logf_SOURCES. * modules/logl-tests (Files): Add tests/test-log.h, tests/minus-zero.h, tests/randoml.c. (Depends-on): Add 'float'. (Makefile.am): Add randoml.c to test_logl_SOURCES. --- diff --git a/ChangeLog b/ChangeLog index 65843d8c6..e873f361a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2012-03-10 Bruno Haible + + log* tests: More tests. + * tests/test-log.h: New file. + * tests/test-log.c: Include , minus-zero.h, test-log.h. + (main): Invoke test_function. + * tests/test-logf.c: Include , minus-zero.h, test-log.h. + (main): Invoke test_function. + * tests/test-logl.c: Include , minus-zero.h, test-log.h. + (main): Invoke test_function. + * modules/log-tests (Files): Add tests/test-log.h, tests/minus-zero.h, + tests/randomd.c. + (Makefile.am): Add randomd.c to test_log_SOURCES. + * modules/logf-tests (Files): Add tests/test-log.h, tests/minus-zero.h, + tests/randomf.c. + (Makefile.am): Add randomf.c to test_logf_SOURCES. + * modules/logl-tests (Files): Add tests/test-log.h, tests/minus-zero.h, + tests/randoml.c. + (Depends-on): Add 'float'. + (Makefile.am): Add randoml.c to test_logl_SOURCES. + 2012-03-09 Bruno Haible logl: Work around OSF/1 5.1 bug. diff --git a/modules/log-tests b/modules/log-tests index d3f5adbdd..cb202ab62 100644 --- a/modules/log-tests +++ b/modules/log-tests @@ -1,7 +1,10 @@ Files: tests/test-log.c +tests/test-log.h +tests/minus-zero.h tests/signature.h tests/macros.h +tests/randomd.c Depends-on: @@ -10,4 +13,5 @@ configure.ac: Makefile.am: TESTS += test-log check_PROGRAMS += test-log +test_log_SOURCES = test-log.c randomd.c test_log_LDADD = $(LDADD) @LOG_LIBM@ diff --git a/modules/logf-tests b/modules/logf-tests index d56c49e54..1dee20b33 100644 --- a/modules/logf-tests +++ b/modules/logf-tests @@ -1,7 +1,10 @@ Files: tests/test-logf.c +tests/test-log.h +tests/minus-zero.h tests/signature.h tests/macros.h +tests/randomf.c Depends-on: @@ -10,4 +13,5 @@ configure.ac: Makefile.am: TESTS += test-logf check_PROGRAMS += test-logf +test_logf_SOURCES = test-logf.c randomf.c test_logf_LDADD = $(LDADD) @LOGF_LIBM@ diff --git a/modules/logl-tests b/modules/logl-tests index 805a3c443..a574090b3 100644 --- a/modules/logl-tests +++ b/modules/logl-tests @@ -1,14 +1,19 @@ Files: tests/test-logl.c +tests/test-log.h +tests/minus-zero.h tests/signature.h tests/macros.h +tests/randoml.c Depends-on: fpucw +float configure.ac: Makefile.am: TESTS += test-logl check_PROGRAMS += test-logl +test_logl_SOURCES = test-logl.c randoml.c test_logl_LDADD = $(LDADD) @LOGL_LIBM@ diff --git a/tests/test-log.c b/tests/test-log.c index 67774b39b..b8c190851 100644 --- a/tests/test-log.c +++ b/tests/test-log.c @@ -23,10 +23,19 @@ #include "signature.h" SIGNATURE_CHECK (log, double, (double)); +#include + +#include "minus-zero.h" #include "macros.h" -volatile double x; -double y; +#define DOUBLE double +#define HUGEVAL HUGE_VAL +#define L_(literal) literal +#define MANT_DIG DBL_MANT_DIG +#define MINUS_ZERO minus_zerod +#define LOG log +#define RANDOM randomd +#include "test-log.h" int main () @@ -36,5 +45,7 @@ main () y = log (x); ASSERT (y >= -0.5108256238 && y <= -0.5108256237); + test_function (); + return 0; } diff --git a/tests/test-log.h b/tests/test-log.h new file mode 100644 index 000000000..32b596ebc --- /dev/null +++ b/tests/test-log.h @@ -0,0 +1,103 @@ +/* Test of log*() function family. + 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) +{ + int i; + int j; + const DOUBLE TWO_MANT_DIG = + /* Assume MANT_DIG <= 5 * 31. + Use the identity + n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */ + (DOUBLE) (1U << ((MANT_DIG - 1) / 5)) + * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5)) + * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5)) + * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5)) + * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5)); + + { + DOUBLE z = LOG (L_(0.0)); + ASSERT (z == - HUGEVAL); + } + { + DOUBLE z = LOG (MINUS_ZERO); + ASSERT (z == - HUGEVAL); + } + + /* Randomized tests. */ + { + /* Error bound, in ulps. */ + const DOUBLE err_bound = + (sizeof (DOUBLE) == sizeof (long double) ? +#if defined __i386__ && defined __FreeBSD__ + /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of + precision in the compiler but 64 bits of precision at runtime. See + . + The compiler has truncated all 'long double' literals in logl.c to + 53 bits of precision. */ + L_(40.0) +#else + L_(3.0) +#endif + : L_(3.0)); + + for (i = 0; i < SIZEOF (RANDOM); i++) + { + DOUBLE x = L_(16.0) * RANDOM[i] + L_(1.0); /* 1.0 <= x <= 17.0 */ + DOUBLE y = LOG (x); + DOUBLE z = LOG (L_(1.0) / x); + DOUBLE err = y + z; + ASSERT (y >= L_(0.0)); + ASSERT (z <= L_(0.0)); + ASSERT (err > - err_bound / TWO_MANT_DIG + && err < err_bound / TWO_MANT_DIG); + } + } + + { + /* Error bound, in ulps. */ + const DOUBLE err_bound = + (sizeof (DOUBLE) == sizeof (long double) ? +#if defined __i386__ && defined __FreeBSD__ + /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of + precision in the compiler but 64 bits of precision at runtime. See + . + The compiler has truncated all 'long double' literals in logl.c to + 53 bits of precision. */ + L_(85.0) +#else + L_(7.0) +#endif + : L_(7.0)); + + for (i = 0; i < SIZEOF (RANDOM) / 5; i++) + for (j = 0; j < SIZEOF (RANDOM) / 5; j++) + { + DOUBLE x = L_(17.0) / (L_(16.0) - L_(15.0) * RANDOM[i]) - L_(1.0); + DOUBLE y = L_(17.0) / (L_(16.0) - L_(15.0) * RANDOM[j]) - L_(1.0); + /* 1/16 <= x,y <= 16 */ + DOUBLE z = L_(1.0) / (x * y); + /* Approximately x * y * z = 1. */ + DOUBLE err = LOG (x) + LOG (y) + LOG (z); + ASSERT (err > - err_bound / TWO_MANT_DIG + && err < err_bound / TWO_MANT_DIG); + } + } +} + +volatile DOUBLE x; +DOUBLE y; diff --git a/tests/test-logf.c b/tests/test-logf.c index 78777af03..e9d040628 100644 --- a/tests/test-logf.c +++ b/tests/test-logf.c @@ -23,10 +23,19 @@ #include "signature.h" SIGNATURE_CHECK (logf, float, (float)); +#include + +#include "minus-zero.h" #include "macros.h" -volatile float x; -float y; +#define DOUBLE float +#define HUGEVAL HUGE_VALF +#define L_(literal) literal##f +#define MANT_DIG FLT_MANT_DIG +#define MINUS_ZERO minus_zerof +#define LOG logf +#define RANDOM randomf +#include "test-log.h" int main () @@ -36,5 +45,7 @@ main () y = logf (x); ASSERT (y >= -0.5108257f && y <= -0.5108256f); + test_function (); + return 0; } diff --git a/tests/test-logl.c b/tests/test-logl.c index 9bc923bc0..9c6f6c746 100644 --- a/tests/test-logl.c +++ b/tests/test-logl.c @@ -23,11 +23,20 @@ #include "signature.h" SIGNATURE_CHECK (logl, long double, (long double)); +#include + #include "fpucw.h" +#include "minus-zero.h" #include "macros.h" -volatile long double x; -long double y; +#define DOUBLE long double +#define HUGEVAL HUGE_VALL +#define L_(literal) literal##L +#define MANT_DIG LDBL_MANT_DIG +#define MINUS_ZERO minus_zerol +#define LOG logl +#define RANDOM randoml +#include "test-log.h" int main () @@ -41,5 +50,7 @@ main () y = logl (x); ASSERT (y >= -0.5108256238L && y <= -0.5108256237L); + test_function (); + return 0; }