Mercurial > hg > octave-lyh > gnulib-hg
changeset 16634:f7facf65bb70
log* tests: More tests.
* tests/test-log.h: New file.
* tests/test-log.c: Include <float.h>, minus-zero.h, test-log.h.
(main): Invoke test_function.
* tests/test-logf.c: Include <float.h>, minus-zero.h, test-log.h.
(main): Invoke test_function.
* tests/test-logl.c: Include <float.h>, 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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 10 Mar 2012 10:56:05 +0100 |
parents | 833042aa7d55 |
children | a0aac1eb3f2d |
files | ChangeLog modules/log-tests modules/logf-tests modules/logl-tests tests/test-log.c tests/test-log.h tests/test-logf.c tests/test-logl.c |
diffstat | 8 files changed, 176 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2012-03-10 Bruno Haible <bruno@clisp.org> + + log* tests: More tests. + * tests/test-log.h: New file. + * tests/test-log.c: Include <float.h>, minus-zero.h, test-log.h. + (main): Invoke test_function. + * tests/test-logf.c: Include <float.h>, minus-zero.h, test-log.h. + (main): Invoke test_function. + * tests/test-logl.c: Include <float.h>, 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 <bruno@clisp.org> logl: Work around OSF/1 5.1 bug.
--- 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 @@ Makefile.am: TESTS += test-log check_PROGRAMS += test-log +test_log_SOURCES = test-log.c randomd.c test_log_LDADD = $(LDADD) @LOG_LIBM@
--- 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 @@ Makefile.am: TESTS += test-logf check_PROGRAMS += test-logf +test_logf_SOURCES = test-logf.c randomf.c test_logf_LDADD = $(LDADD) @LOGF_LIBM@
--- 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@
--- a/tests/test-log.c +++ b/tests/test-log.c @@ -23,10 +23,19 @@ #include "signature.h" SIGNATURE_CHECK (log, double, (double)); +#include <float.h> + +#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 @@ y = log (x); ASSERT (y >= -0.5108256238 && y <= -0.5108256237); + test_function (); + return 0; }
new file mode 100644 --- /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 <http://www.gnu.org/licenses/>. */ + +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 + <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>. + 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 + <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>. + 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;
--- a/tests/test-logf.c +++ b/tests/test-logf.c @@ -23,10 +23,19 @@ #include "signature.h" SIGNATURE_CHECK (logf, float, (float)); +#include <float.h> + +#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 @@ y = logf (x); ASSERT (y >= -0.5108257f && y <= -0.5108256f); + test_function (); + return 0; }
--- 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 <float.h> + #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 @@ y = logl (x); ASSERT (y >= -0.5108256238L && y <= -0.5108256237L); + test_function (); + return 0; }