Mercurial > hg > octave-lyh > gnulib-hg
changeset 16575:2faf2762788a
cbrt* tests: More tests.
* tests/test-cbrt.h: New file.
* tests/test-cbrt.c: Include <float.h> and test-cbrt.h.
(main): Invoke test_function.
* tests/test-cbrtf.c: Include <float.h> and test-cbrt.h.
(main): Invoke test_function.
* tests/test-cbrtl.c: Include <float.h> and test-cbrt.h.
(main): Invoke test_function.
* modules/cbrt-tests (Files): Add tests/test-cbrt.h, tests/randomd.c.
(Makefile.am): Add randomd.c to test_cbrt_SOURCES.
* modules/cbrtf-tests (Files): Add tests/test-cbrt.h, tests/randomf.c.
(Makefile.am): Add randomf.c to test_cbrtf_SOURCES.
* modules/cbrtl-tests (Files): Add tests/test-cbrt.h, tests/randoml.c.
(Depends-on): Add 'float'.
(Makefile.am): Add randoml.c to test_cbrtl_SOURCES.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 05 Mar 2012 14:16:38 +0100 |
parents | 4acf461e0a81 |
children | 6c7c671909d3 |
files | ChangeLog modules/cbrt-tests modules/cbrtf-tests modules/cbrtl-tests tests/test-cbrt.c tests/test-cbrt.h tests/test-cbrtf.c tests/test-cbrtl.c |
diffstat | 8 files changed, 117 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2012-03-05 Bruno Haible <bruno@clisp.org> + + cbrt* tests: More tests. + * tests/test-cbrt.h: New file. + * tests/test-cbrt.c: Include <float.h> and test-cbrt.h. + (main): Invoke test_function. + * tests/test-cbrtf.c: Include <float.h> and test-cbrt.h. + (main): Invoke test_function. + * tests/test-cbrtl.c: Include <float.h> and test-cbrt.h. + (main): Invoke test_function. + * modules/cbrt-tests (Files): Add tests/test-cbrt.h, tests/randomd.c. + (Makefile.am): Add randomd.c to test_cbrt_SOURCES. + * modules/cbrtf-tests (Files): Add tests/test-cbrt.h, tests/randomf.c. + (Makefile.am): Add randomf.c to test_cbrtf_SOURCES. + * modules/cbrtl-tests (Files): Add tests/test-cbrt.h, tests/randoml.c. + (Depends-on): Add 'float'. + (Makefile.am): Add randoml.c to test_cbrtl_SOURCES. + 2012-03-05 Bruno Haible <bruno@clisp.org> hypot* tests: More tests.
--- a/modules/cbrt-tests +++ b/modules/cbrt-tests @@ -1,7 +1,9 @@ Files: tests/test-cbrt.c +tests/test-cbrt.h tests/signature.h tests/macros.h +tests/randomd.c Depends-on: @@ -10,4 +12,5 @@ Makefile.am: TESTS += test-cbrt check_PROGRAMS += test-cbrt +test_cbrt_SOURCES = test-cbrt.c randomd.c test_cbrt_LDADD = $(LDADD) @CBRT_LIBM@
--- a/modules/cbrtf-tests +++ b/modules/cbrtf-tests @@ -1,7 +1,9 @@ Files: tests/test-cbrtf.c +tests/test-cbrt.h tests/signature.h tests/macros.h +tests/randomf.c Depends-on: @@ -10,4 +12,5 @@ Makefile.am: TESTS += test-cbrtf check_PROGRAMS += test-cbrtf +test_cbrtf_SOURCES = test-cbrtf.c randomf.c test_cbrtf_LDADD = $(LDADD) @CBRTF_LIBM@
--- a/modules/cbrtl-tests +++ b/modules/cbrtl-tests @@ -1,13 +1,17 @@ Files: tests/test-cbrtl.c +tests/test-cbrt.h tests/signature.h tests/macros.h +tests/randoml.c Depends-on: +float configure.ac: Makefile.am: TESTS += test-cbrtl check_PROGRAMS += test-cbrtl +test_cbrtl_SOURCES = test-cbrtl.c randoml.c test_cbrtl_LDADD = $(LDADD) @CBRTL_LIBM@
--- a/tests/test-cbrt.c +++ b/tests/test-cbrt.c @@ -23,10 +23,16 @@ #include "signature.h" SIGNATURE_CHECK (cbrt, double, (double)); +#include <float.h> + #include "macros.h" -volatile double x; -double y; +#define DOUBLE double +#define L_(literal) literal +#define MANT_DIG DBL_MANT_DIG +#define CBRT cbrt +#define RANDOM randomd +#include "test-cbrt.h" int main () @@ -36,5 +42,7 @@ y = cbrt (x); ASSERT (y >= 0.8434326653 && y <= 0.8434326654); + test_function (); + return 0; }
new file mode 100644 --- /dev/null +++ b/tests/test-cbrt.h @@ -0,0 +1,59 @@ +/* Test of cbrt*() 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)); + + /* Randomized tests. */ + for (i = 0; i < SIZEOF (RANDOM); i++) + { + DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */ + DOUBLE y = CBRT (x); + DOUBLE err = y * y * y - x; + ASSERT (err > - L_(4.0) * L_(16.0) / TWO_MANT_DIG + && err < L_(4.0) * L_(16.0) / TWO_MANT_DIG); + } + + for (i = 0; i < SIZEOF (RANDOM) / 5; i++) + for (j = 0; j < SIZEOF (RANDOM) / 5; j++) + { + DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */ + DOUBLE y = L_(32.0) * RANDOM[j] - L_(16.0); /* -16.0 <= y <= 16.0 */ + if (x != L_(0.0) && y != L_(0.0)) + { + DOUBLE z = L_(1.0) / (x * y); + /* Approximately x * y * z = 1. */ + DOUBLE p = CBRT (x) * CBRT (y) * CBRT (z); + ASSERT (p > L_(1.0) - L_(8.0) / TWO_MANT_DIG + && p < L_(1.0) + L_(8.0) / TWO_MANT_DIG); + } + } +} + +volatile DOUBLE x; +DOUBLE y;
--- a/tests/test-cbrtf.c +++ b/tests/test-cbrtf.c @@ -23,10 +23,16 @@ #include "signature.h" SIGNATURE_CHECK (cbrtf, float, (float)); +#include <float.h> + #include "macros.h" -volatile float x; -float y; +#define DOUBLE float +#define L_(literal) literal##f +#define MANT_DIG FLT_MANT_DIG +#define CBRT cbrtf +#define RANDOM randomf +#include "test-cbrt.h" int main () @@ -36,5 +42,7 @@ y = cbrtf (x); ASSERT (y >= 0.84343266f && y <= 0.84343270f); + test_function (); + return 0; }
--- a/tests/test-cbrtl.c +++ b/tests/test-cbrtl.c @@ -23,10 +23,16 @@ #include "signature.h" SIGNATURE_CHECK (cbrtl, long double, (long double)); +#include <float.h> + #include "macros.h" -volatile long double x; -long double y; +#define DOUBLE long double +#define L_(literal) literal##L +#define MANT_DIG DBL_MANT_DIG +#define CBRT cbrtl +#define RANDOM randoml +#include "test-cbrt.h" int main () @@ -36,5 +42,7 @@ y = cbrtl (x); ASSERT (y >= 0.8434326653L && y <= 0.8434326654L); + test_function (); + return 0; }