* 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>
+
+ 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.
Files:
tests/test-cbrt.c
+tests/test-cbrt.h
tests/signature.h
tests/macros.h
+tests/randomd.c
Depends-on:
Makefile.am:
TESTS += test-cbrt
check_PROGRAMS += test-cbrt
+test_cbrt_SOURCES = test-cbrt.c randomd.c
test_cbrt_LDADD = $(LDADD) @CBRT_LIBM@
Files:
tests/test-cbrtf.c
+tests/test-cbrt.h
tests/signature.h
tests/macros.h
+tests/randomf.c
Depends-on:
Makefile.am:
TESTS += test-cbrtf
check_PROGRAMS += test-cbrtf
+test_cbrtf_SOURCES = test-cbrtf.c randomf.c
test_cbrtf_LDADD = $(LDADD) @CBRTF_LIBM@
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@
#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 ()
y = cbrt (x);
ASSERT (y >= 0.8434326653 && y <= 0.8434326654);
+ test_function ();
+
return 0;
}
--- /dev/null
+/* 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;
#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 ()
y = cbrtf (x);
ASSERT (y >= 0.84343266f && y <= 0.84343270f);
+ test_function ();
+
return 0;
}
#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 ()
y = cbrtl (x);
ASSERT (y >= 0.8434326653L && y <= 0.8434326654L);
+ test_function ();
+
return 0;
}