Mercurial > hg > octave-lojdl > gnulib-hg
changeset 16570:91377475ee5d
sqrt* tests: More tests.
* tests/test-sqrt.h: New file.
* tests/test-sqrt.c: Include <float.h> and test-sqrt.h.
(main): Invoke test_function.
* tests/test-sqrtf.c: Include <float.h> and test-sqrt.h.
(main): Invoke test_function.
* tests/test-sqrtl.c: Include <float.h> and test-sqrt.h.
(main): Invoke test_function.
* modules/sqrt-tests (Files): Add tests/test-sqrt.h, tests/randomd.c.
(Makefile.am): Add randomd.c to test_sqrt_SOURCES.
* modules/sqrtf-tests (Files): Add tests/test-sqrt.h, tests/randomf.c.
(Makefile.am): Add randomf.c to test_sqrtf_SOURCES.
* modules/sqrtl-tests (Files): Add tests/test-sqrt.h, tests/randoml.c.
(Depends-on): Add 'float'.
(Makefile.am): Add randoml.c to test_sqrtl_SOURCES.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 05 Mar 2012 02:14:30 +0100 |
parents | 1f283a634cf1 |
children | 8e8c9d0c02cb |
files | ChangeLog modules/sqrt-tests modules/sqrtf-tests modules/sqrtl-tests tests/test-sqrt.c tests/test-sqrt.h tests/test-sqrtf.c tests/test-sqrtl.c |
diffstat | 8 files changed, 118 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,22 @@ -2012-03-03 Bruno Haible <bruno@clisp.org> +2012-03-04 Bruno Haible <bruno@clisp.org> + + sqrt* tests: More tests. + * tests/test-sqrt.h: New file. + * tests/test-sqrt.c: Include <float.h> and test-sqrt.h. + (main): Invoke test_function. + * tests/test-sqrtf.c: Include <float.h> and test-sqrt.h. + (main): Invoke test_function. + * tests/test-sqrtl.c: Include <float.h> and test-sqrt.h. + (main): Invoke test_function. + * modules/sqrt-tests (Files): Add tests/test-sqrt.h, tests/randomd.c. + (Makefile.am): Add randomd.c to test_sqrt_SOURCES. + * modules/sqrtf-tests (Files): Add tests/test-sqrt.h, tests/randomf.c. + (Makefile.am): Add randomf.c to test_sqrtf_SOURCES. + * modules/sqrtl-tests (Files): Add tests/test-sqrt.h, tests/randoml.c. + (Depends-on): Add 'float'. + (Makefile.am): Add randoml.c to test_sqrtl_SOURCES. + +2012-03-04 Bruno Haible <bruno@clisp.org> remainder* tests: More tests. * tests/test-remainder.h: New file, based on tests/test-fmod.h.
--- a/modules/sqrt-tests +++ b/modules/sqrt-tests @@ -1,7 +1,9 @@ Files: tests/test-sqrt.c +tests/test-sqrt.h tests/signature.h tests/macros.h +tests/randomd.c Depends-on: @@ -10,4 +12,5 @@ Makefile.am: TESTS += test-sqrt check_PROGRAMS += test-sqrt +test_sqrt_SOURCES = test-sqrt.c randomd.c test_sqrt_LDADD = $(LDADD) @SQRT_LIBM@
--- a/modules/sqrtf-tests +++ b/modules/sqrtf-tests @@ -1,7 +1,9 @@ Files: tests/test-sqrtf.c +tests/test-sqrt.h tests/signature.h tests/macros.h +tests/randomf.c Depends-on: @@ -10,4 +12,5 @@ Makefile.am: TESTS += test-sqrtf check_PROGRAMS += test-sqrtf +test_sqrtf_SOURCES = test-sqrtf.c randomf.c test_sqrtf_LDADD = $(LDADD) @SQRTF_LIBM@
--- a/modules/sqrtl-tests +++ b/modules/sqrtl-tests @@ -1,14 +1,18 @@ Files: tests/test-sqrtl.c +tests/test-sqrt.h tests/signature.h tests/macros.h +tests/randoml.c Depends-on: fpucw +float configure.ac: Makefile.am: TESTS += test-sqrtl check_PROGRAMS += test-sqrtl +test_sqrtl_SOURCES = test-sqrtl.c randoml.c test_sqrtl_LDADD = $(LDADD) @SQRTL_LIBM@
--- a/tests/test-sqrt.c +++ b/tests/test-sqrt.c @@ -23,10 +23,16 @@ #include "signature.h" SIGNATURE_CHECK (sqrt, 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 SQRT sqrt +#define RANDOM randomd +#include "test-sqrt.h" int main () @@ -36,5 +42,7 @@ y = sqrt (x); ASSERT (y >= 0.7745966692 && y <= 0.7745966693); + test_function (); + return 0; }
new file mode 100644 --- /dev/null +++ b/tests/test-sqrt.h @@ -0,0 +1,59 @@ +/* Test of sqrt*() 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_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */ + DOUBLE y = SQRT (x); + DOUBLE z = y * y - x; + ASSERT (z > - L_(16.0) / TWO_MANT_DIG + && z < L_(16.0) / TWO_MANT_DIG); + } + + for (i = 0; i < SIZEOF (RANDOM) / 4; i++) + for (j = 0; j < SIZEOF (RANDOM) / 4; j++) + { + DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */ + DOUBLE y = L_(16.0) * RANDOM[j]; /* 0.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 = SQRT (x) * SQRT (y) * SQRT (z); + ASSERT (p > L_(1.0) - L_(4.0) / TWO_MANT_DIG + && p < L_(1.0) + L_(4.0) / TWO_MANT_DIG); + } + } +} + +volatile DOUBLE x; +DOUBLE y;
--- a/tests/test-sqrtf.c +++ b/tests/test-sqrtf.c @@ -23,10 +23,16 @@ #include "signature.h" SIGNATURE_CHECK (sqrtf, 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 SQRT sqrtf +#define RANDOM randomf +#include "test-sqrt.h" int main () @@ -36,5 +42,7 @@ y = sqrtf (x); ASSERT (y >= 0.7745966f && y <= 0.7745967f); + test_function (); + return 0; }
--- a/tests/test-sqrtl.c +++ b/tests/test-sqrtl.c @@ -23,11 +23,17 @@ #include "signature.h" SIGNATURE_CHECK (sqrtl, long double, (long double)); +#include <float.h> + #include "fpucw.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 SQRT sqrtl +#define RANDOM randoml +#include "test-sqrt.h" int main () @@ -41,5 +47,7 @@ y = sqrtl (x); ASSERT (y >= 0.7745966692L && y <= 0.7745966693L); + test_function (); + return 0; }