summaryrefslogtreecommitdiffstats
path: root/tools/regression/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression/lib')
-rw-r--r--tools/regression/lib/msun/Makefile3
-rw-r--r--tools/regression/lib/msun/test-ctrig.c540
-rw-r--r--tools/regression/lib/msun/test-ctrig.t10
-rw-r--r--tools/regression/lib/msun/test-fma.c115
-rw-r--r--tools/regression/lib/msun/test-logarithm.c31
-rw-r--r--tools/regression/lib/msun/test-nearbyint.c134
6 files changed, 803 insertions, 30 deletions
diff --git a/tools/regression/lib/msun/Makefile b/tools/regression/lib/msun/Makefile
index 155fd31..261b1cb 100644
--- a/tools/regression/lib/msun/Makefile
+++ b/tools/regression/lib/msun/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
-TESTS= test-cexp test-conj test-csqrt test-exponential test-fenv test-fma \
+TESTS= test-cexp test-conj test-csqrt test-ctrig \
+ test-exponential test-fenv test-fma \
test-fmaxmin test-ilogb test-invtrig test-logarithm test-lrint \
test-lround test-nan test-nearbyint test-next test-rem test-trig
CFLAGS+= -O0 -lm
diff --git a/tools/regression/lib/msun/test-ctrig.c b/tools/regression/lib/msun/test-ctrig.c
new file mode 100644
index 0000000..ed78661
--- /dev/null
+++ b/tools/regression/lib/msun/test-ctrig.c
@@ -0,0 +1,540 @@
+/*-
+ * Copyright (c) 2008-2011 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Tests for csin[h](), ccos[h](), and ctan[h]().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <complex.h>
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
+#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+ FE_OVERFLOW | FE_UNDERFLOW)
+#define OPT_INVALID (ALL_STD_EXCEPT & ~FE_INVALID)
+#define OPT_INEXACT (ALL_STD_EXCEPT & ~FE_INEXACT)
+#define FLT_ULP() ldexpl(1.0, 1 - FLT_MANT_DIG)
+#define DBL_ULP() ldexpl(1.0, 1 - DBL_MANT_DIG)
+#define LDBL_ULP() ldexpl(1.0, 1 - LDBL_MANT_DIG)
+
+#pragma STDC FENV_ACCESS ON
+#pragma STDC CX_LIMITED_RANGE OFF
+
+/*
+ * XXX gcc implements complex multiplication incorrectly. In
+ * particular, it implements it as if the CX_LIMITED_RANGE pragma
+ * were ON. Consequently, we need this function to form numbers
+ * such as x + INFINITY * I, since gcc evalutes INFINITY * I as
+ * NaN + INFINITY * I.
+ */
+static inline long double complex
+cpackl(long double x, long double y)
+{
+ long double complex z;
+
+ __real__ z = x;
+ __imag__ z = y;
+ return (z);
+}
+
+/* Flags that determine whether to check the signs of the result. */
+#define CS_REAL 1
+#define CS_IMAG 2
+#define CS_BOTH (CS_REAL | CS_IMAG)
+
+#ifdef DEBUG
+#define debug(...) printf(__VA_ARGS__)
+#else
+#define debug(...) (void)0
+#endif
+
+/*
+ * Test that a function returns the correct value and sets the
+ * exception flags correctly. The exceptmask specifies which
+ * exceptions we should check. We need to be lenient for several
+ * reasons, but mainly because on some architectures it's impossible
+ * to raise FE_OVERFLOW without raising FE_INEXACT.
+ *
+ * These are macros instead of functions so that assert provides more
+ * meaningful error messages.
+ *
+ * XXX The volatile here is to avoid gcc's bogus constant folding and work
+ * around the lack of support for the FENV_ACCESS pragma.
+ */
+#define test_p(func, z, result, exceptmask, excepts, checksign) do { \
+ volatile long double complex _d = z; \
+ debug(" testing %s(%Lg + %Lg I) == %Lg + %Lg I\n", #func, \
+ creall(_d), cimagl(_d), creall(result), cimagl(result)); \
+ assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
+ assert(cfpequal((func)(_d), (result), (checksign))); \
+ assert(((func), fetestexcept(exceptmask) == (excepts))); \
+} while (0)
+
+/*
+ * Test within a given tolerance. The tolerance indicates relative error
+ * in ulps. If result is 0, however, it measures absolute error in units
+ * of <format>_EPSILON.
+ */
+#define test_p_tol(func, z, result, tol) do { \
+ volatile long double complex _d = z; \
+ debug(" testing %s(%Lg + %Lg I) ~= %Lg + %Lg I\n", #func, \
+ creall(_d), cimagl(_d), creall(result), cimagl(result)); \
+ assert(cfpequal_tol((func)(_d), (result), (tol))); \
+} while (0)
+
+/* These wrappers apply the identities f(conj(z)) = conj(f(z)). */
+#define test(func, z, result, exceptmask, excepts, checksign) do { \
+ test_p(func, z, result, exceptmask, excepts, checksign); \
+ test_p(func, conjl(z), conjl(result), exceptmask, excepts, checksign); \
+} while (0)
+#define test_tol(func, z, result, tol) do { \
+ test_p_tol(func, z, result, tol); \
+ test_p_tol(func, conjl(z), conjl(result), tol); \
+} while (0)
+
+/* Test the given function in all precisions. */
+#define testall(func, x, result, exceptmask, excepts, checksign) do { \
+ test(func, x, result, exceptmask, excepts, checksign); \
+ test(func##f, x, result, exceptmask, excepts, checksign); \
+} while (0)
+#define testall_odd(func, x, result, exceptmask, excepts, checksign) do { \
+ testall(func, x, result, exceptmask, excepts, checksign); \
+ testall(func, -x, -result, exceptmask, excepts, checksign); \
+} while (0)
+#define testall_even(func, x, result, exceptmask, excepts, checksign) do { \
+ testall(func, x, result, exceptmask, excepts, checksign); \
+ testall(func, -x, result, exceptmask, excepts, checksign); \
+} while (0)
+
+/*
+ * Test the given function in all precisions, within a given tolerance.
+ * The tolerance is specified in ulps.
+ */
+#define testall_tol(func, x, result, tol) do { \
+ test_tol(func, x, result, tol * DBL_ULP()); \
+ test_tol(func##f, x, result, tol * FLT_ULP()); \
+} while (0)
+#define testall_odd_tol(func, x, result, tol) do { \
+ test_tol(func, x, result, tol * DBL_ULP()); \
+ test_tol(func, -x, -result, tol * DBL_ULP()); \
+} while (0)
+#define testall_even_tol(func, x, result, tol) do { \
+ test_tol(func, x, result, tol * DBL_ULP()); \
+ test_tol(func, -x, result, tol * DBL_ULP()); \
+} while (0)
+
+/*
+ * Determine whether x and y are equal, with two special rules:
+ * +0.0 != -0.0
+ * NaN == NaN
+ * If checksign is 0, we compare the absolute values instead.
+ */
+static int
+fpequal(long double x, long double y, int checksign)
+{
+ if (isnan(x) && isnan(y))
+ return (1);
+ if (checksign)
+ return (x == y && !signbit(x) == !signbit(y));
+ else
+ return (fabsl(x) == fabsl(y));
+}
+
+static int
+fpequal_tol(long double x, long double y, long double tol)
+{
+ fenv_t env;
+ int ret;
+
+ if (isnan(x) && isnan(y))
+ return (1);
+ if (!signbit(x) != !signbit(y) && tol == 0)
+ return (0);
+ if (x == y)
+ return (1);
+ if (tol == 0)
+ return (0);
+
+ /* Hard case: need to check the tolerance. */
+ feholdexcept(&env);
+ /*
+ * For our purposes here, if y=0, we interpret tol as an absolute
+ * tolerance. This is to account for roundoff in the input, e.g.,
+ * cos(Pi/2) ~= 0.
+ */
+ if (y == 0.0)
+ ret = fabsl(x - y) <= fabsl(tol);
+ else
+ ret = fabsl(x - y) <= fabsl(y * tol);
+ fesetenv(&env);
+ return (ret);
+}
+
+static int
+cfpequal(long double complex x, long double complex y, int checksign)
+{
+ return (fpequal(creal(x), creal(y), checksign & CS_REAL)
+ && fpequal(cimag(x), cimag(y), checksign & CS_IMAG));
+}
+
+static int
+cfpequal_tol(long double complex x, long double complex y, long double tol)
+{
+ return (fpequal_tol(creal(x), creal(y), tol)
+ && fpequal_tol(cimag(x), cimag(y), tol));
+}
+
+
+/* Tests for 0 */
+void
+test_zero(void)
+{
+ long double complex zero = cpackl(0.0, 0.0);
+
+ /* csinh(0) = ctanh(0) = 0; ccosh(0) = 1 (no exceptions raised) */
+ testall_odd(csinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
+ testall_odd(csin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
+ testall_even(ccosh, zero, 1.0, ALL_STD_EXCEPT, 0, CS_BOTH);
+ testall_even(ccos, zero, cpackl(1.0, -0.0), ALL_STD_EXCEPT, 0, CS_BOTH);
+ testall_odd(ctanh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
+ testall_odd(ctan, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
+}
+
+/*
+ * Tests for NaN inputs.
+ */
+void
+test_nan()
+{
+ long double complex nan_nan = cpackl(NAN, NAN);
+ long double complex z;
+
+ /*
+ * IN CSINH CCOSH CTANH
+ * NaN,NaN NaN,NaN NaN,NaN NaN,NaN
+ * finite,NaN NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
+ * NaN,finite NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
+ * NaN,Inf NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
+ * Inf,NaN +-Inf,NaN Inf,NaN 1,+-0
+ * 0,NaN +-0,NaN NaN,+-0 NaN,NaN [inval]
+ * NaN,0 NaN,0 NaN,+-0 NaN,0
+ */
+ z = nan_nan;
+ testall_odd(csinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
+ testall_even(ccosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
+ testall_odd(ctanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
+ testall_odd(csin, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
+ testall_even(ccos, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
+ testall_odd(ctan, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
+
+ z = cpackl(42, NAN);
+ testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
+ /* XXX We allow a spurious inexact exception here. */
+ testall_odd(ctanh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
+ testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
+
+ z = cpackl(NAN, 42);
+ testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
+ /* XXX We allow a spurious inexact exception here. */
+ testall_odd(ctan, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
+
+ z = cpackl(NAN, INFINITY);
+ testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(csin, z, cpackl(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
+ testall_even(ccos, z, cpackl(INFINITY, NAN), ALL_STD_EXCEPT, 0,
+ CS_IMAG);
+ testall_odd(ctan, z, cpackl(0, 1), ALL_STD_EXCEPT, 0, CS_IMAG);
+
+ z = cpackl(INFINITY, NAN);
+ testall_odd(csinh, z, cpackl(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0);
+ testall_even(ccosh, z, cpackl(INFINITY, NAN), ALL_STD_EXCEPT, 0,
+ CS_REAL);
+ testall_odd(ctanh, z, cpackl(1, 0), ALL_STD_EXCEPT, 0, CS_REAL);
+ testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
+
+ z = cpackl(0, NAN);
+ testall_odd(csinh, z, cpackl(0, NAN), ALL_STD_EXCEPT, 0, 0);
+ testall_even(ccosh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
+ testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(csin, z, cpackl(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
+ testall_even(ccos, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
+ testall_odd(ctan, z, cpackl(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
+
+ z = cpackl(NAN, 0);
+ testall_odd(csinh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
+ testall_even(ccosh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
+ testall_odd(ctanh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
+ testall_odd(csin, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
+ testall_even(ccos, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
+ testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
+}
+
+void
+test_inf(void)
+{
+ static const long double finites[] = {
+ 0, M_PI / 4, 3 * M_PI / 4, 5 * M_PI / 4,
+ };
+ long double complex z, c, s;
+ int i;
+
+ /*
+ * IN CSINH CCOSH CTANH
+ * Inf,Inf +-Inf,NaN inval +-Inf,NaN inval 1,+-0
+ * Inf,finite Inf cis(finite) Inf cis(finite) 1,0 sin(2 finite)
+ * 0,Inf +-0,NaN inval NaN,+-0 inval NaN,NaN inval
+ * finite,Inf NaN,NaN inval NaN,NaN inval NaN,NaN inval
+ */
+ z = cpackl(INFINITY, INFINITY);
+ testall_odd(csinh, z, cpackl(INFINITY, NAN),
+ ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_even(ccosh, z, cpackl(INFINITY, NAN),
+ ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_odd(ctanh, z, cpackl(1, 0), ALL_STD_EXCEPT, 0, CS_REAL);
+ testall_odd(csin, z, cpackl(NAN, INFINITY),
+ ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_even(ccos, z, cpackl(INFINITY, NAN),
+ ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_odd(ctan, z, cpackl(0, 1), ALL_STD_EXCEPT, 0, CS_REAL);
+
+ /* XXX We allow spurious inexact exceptions here (hard to avoid). */
+ for (i = 0; i < sizeof(finites) / sizeof(finites[0]); i++) {
+ z = cpackl(INFINITY, finites[i]);
+ c = INFINITY * cosl(finites[i]);
+ s = finites[i] == 0 ? finites[i] : INFINITY * sinl(finites[i]);
+ testall_odd(csinh, z, cpackl(c, s), OPT_INEXACT, 0, CS_BOTH);
+ testall_even(ccosh, z, cpackl(c, s), OPT_INEXACT, 0, CS_BOTH);
+ testall_odd(ctanh, z, cpackl(1, 0 * sin(finites[i] * 2)),
+ OPT_INEXACT, 0, CS_BOTH);
+ z = cpackl(finites[i], INFINITY);
+ testall_odd(csin, z, cpackl(s, c), OPT_INEXACT, 0, CS_BOTH);
+ testall_even(ccos, z, cpackl(c, -s), OPT_INEXACT, 0, CS_BOTH);
+ testall_odd(ctan, z, cpackl(0 * sin(finites[i] * 2), 1),
+ OPT_INEXACT, 0, CS_BOTH);
+ }
+
+ z = cpackl(0, INFINITY);
+ testall_odd(csinh, z, cpackl(0, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_even(ccosh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_odd(ctanh, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ z = cpackl(INFINITY, 0);
+ testall_odd(csin, z, cpackl(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_even(ccos, z, cpackl(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_odd(ctan, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+
+ z = cpackl(42, INFINITY);
+ testall_odd(csinh, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_even(ccosh, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ /* XXX We allow a spurious inexact exception here. */
+ testall_odd(ctanh, z, cpackl(NAN, NAN), OPT_INEXACT, FE_INVALID, 0);
+ z = cpackl(INFINITY, 42);
+ testall_odd(csin, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_even(ccos, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ /* XXX We allow a spurious inexact exception here. */
+ testall_odd(ctan, z, cpackl(NAN, NAN), OPT_INEXACT, FE_INVALID, 0);
+}
+
+/* Tests along the real and imaginary axes. */
+void
+test_axes(void)
+{
+ static const long double nums[] = {
+ M_PI / 4, M_PI / 2, 3 * M_PI / 4,
+ 5 * M_PI / 4, 3 * M_PI / 2, 7 * M_PI / 4,
+ };
+ long double complex z;
+ int i;
+
+ for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) {
+ /* Real axis */
+ z = cpackl(nums[i], 0.0);
+ testall_odd_tol(csinh, z, cpackl(sinh(nums[i]), 0), 0);
+ testall_even_tol(ccosh, z, cpackl(cosh(nums[i]), 0), 0);
+ testall_odd_tol(ctanh, z, cpackl(tanh(nums[i]), 0), 1);
+ testall_odd_tol(csin, z, cpackl(sin(nums[i]),
+ copysign(0, cos(nums[i]))), 0);
+ testall_even_tol(ccos, z, cpackl(cos(nums[i]),
+ -copysign(0, sin(nums[i]))), 0);
+ testall_odd_tol(ctan, z, cpackl(tan(nums[i]), 0), 1);
+
+ /* Imaginary axis */
+ z = cpackl(0.0, nums[i]);
+ testall_odd_tol(csinh, z, cpackl(copysign(0, cos(nums[i])),
+ sin(nums[i])), 0);
+ testall_even_tol(ccosh, z, cpackl(cos(nums[i]),
+ copysign(0, sin(nums[i]))), 0);
+ testall_odd_tol(ctanh, z, cpackl(0, tan(nums[i])), 1);
+ testall_odd_tol(csin, z, cpackl(0, sinh(nums[i])), 0);
+ testall_even_tol(ccos, z, cpackl(cosh(nums[i]), -0.0), 0);
+ testall_odd_tol(ctan, z, cpackl(0, tanh(nums[i])), 1);
+ }
+}
+
+void
+test_small(void)
+{
+ /*
+ * z = 0.5 + i Pi/4
+ * sinh(z) = (sinh(0.5) + i cosh(0.5)) * sqrt(2)/2
+ * cosh(z) = (cosh(0.5) + i sinh(0.5)) * sqrt(2)/2
+ * tanh(z) = (2cosh(0.5)sinh(0.5) + i) / (2 cosh(0.5)**2 - 1)
+ * z = -0.5 + i Pi/2
+ * sinh(z) = cosh(0.5)
+ * cosh(z) = -i sinh(0.5)
+ * tanh(z) = -coth(0.5)
+ * z = 1.0 + i 3Pi/4
+ * sinh(z) = (-sinh(1) + i cosh(1)) * sqrt(2)/2
+ * cosh(z) = (-cosh(1) + i sinh(1)) * sqrt(2)/2
+ * tanh(z) = (2cosh(1)sinh(1) - i) / (2cosh(1)**2 - 1)
+ */
+ static const struct {
+ long double a, b;
+ long double sinh_a, sinh_b;
+ long double cosh_a, cosh_b;
+ long double tanh_a, tanh_b;
+ } tests[] = {
+ { 0.5L,
+ 0.78539816339744830961566084581987572L,
+ 0.36847002415910435172083660522240710L,
+ 0.79735196663945774996093142586179334L,
+ 0.79735196663945774996093142586179334L,
+ 0.36847002415910435172083660522240710L,
+ 0.76159415595576488811945828260479359L,
+ 0.64805427366388539957497735322615032L },
+ { -0.5L,
+ 1.57079632679489661923132169163975144L,
+ 0.0L,
+ 1.12762596520638078522622516140267201L,
+ 0.0L,
+ -0.52109530549374736162242562641149156L,
+ -2.16395341373865284877000401021802312L,
+ 0.0L },
+ { 1.0L,
+ 2.35619449019234492884698253745962716L,
+ -0.83099273328405698212637979852748608L,
+ 1.09112278079550143030545602018565236L,
+ -1.09112278079550143030545602018565236L,
+ 0.83099273328405698212637979852748609L,
+ 0.96402758007581688394641372410092315L,
+ -0.26580222883407969212086273981988897L }
+ };
+ long double complex z;
+ int i;
+
+ for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
+ z = cpackl(tests[i].a, tests[i].b);
+ testall_odd_tol(csinh, z,
+ cpackl(tests[i].sinh_a, tests[i].sinh_b), 1.1);
+ testall_even_tol(ccosh, z,
+ cpackl(tests[i].cosh_a, tests[i].cosh_b), 1.1);
+ testall_odd_tol(ctanh, z,
+ cpackl(tests[i].tanh_a, tests[i].tanh_b), 1.1);
+ }
+}
+
+/* Test inputs that might cause overflow in a sloppy implementation. */
+void
+test_large(void)
+{
+ long double complex z;
+
+ /* tanh() uses a threshold around x=22, so check both sides. */
+ z = cpackl(21, 0.78539816339744830961566084581987572L);
+ testall_odd_tol(ctanh, z,
+ cpackl(1.0, 1.14990445285871196133287617611468468e-18L), 1);
+ z++;
+ testall_odd_tol(ctanh, z,
+ cpackl(1.0, 1.55622644822675930314266334585597964e-19L), 1);
+
+ z = cpackl(355, 0.78539816339744830961566084581987572L);
+ testall_odd_tol(ctanh, z,
+ cpackl(1.0, 8.95257245135025991216632140458264468e-309L), 1);
+ z = cpackl(30, 0x1p1023L);
+ testall_odd_tol(ctanh, z,
+ cpackl(1.0, -1.62994325413993477997492170229268382e-26L), 1);
+ z = cpackl(1, 0x1p1023L);
+ testall_odd_tol(ctanh, z,
+ cpackl(0.878606311888306869546254022621986509L,
+ -0.225462792499754505792678258169527424L), 1);
+
+ z = cpackl(710.6, 0.78539816339744830961566084581987572L);
+ testall_odd_tol(csinh, z,
+ cpackl(1.43917579766621073533185387499658944e308L,
+ 1.43917579766621073533185387499658944e308L), 1);
+ testall_even_tol(ccosh, z,
+ cpackl(1.43917579766621073533185387499658944e308L,
+ 1.43917579766621073533185387499658944e308L), 1);
+
+ z = cpackl(1500, 0.78539816339744830961566084581987572L);
+ testall_odd(csinh, z, cpackl(INFINITY, INFINITY), OPT_INEXACT,
+ FE_OVERFLOW, CS_BOTH);
+ testall_even(ccosh, z, cpackl(INFINITY, INFINITY), OPT_INEXACT,
+ FE_OVERFLOW, CS_BOTH);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..6\n");
+
+ test_zero();
+ printf("ok 1 - ctrig zero\n");
+
+ test_nan();
+ printf("ok 2 - ctrig nan\n");
+
+ test_inf();
+ printf("ok 3 - ctrig inf\n");
+
+ test_axes();
+ printf("ok 4 - ctrig axes\n");
+
+ test_small();
+ printf("ok 5 - ctrig small\n");
+
+ test_large();
+ printf("ok 6 - ctrig large\n");
+
+ return (0);
+}
diff --git a/tools/regression/lib/msun/test-ctrig.t b/tools/regression/lib/msun/test-ctrig.t
new file mode 100644
index 0000000..8bdfd03
--- /dev/null
+++ b/tools/regression/lib/msun/test-ctrig.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
diff --git a/tools/regression/lib/msun/test-fma.c b/tools/regression/lib/msun/test-fma.c
index 00620f8..1237a60 100644
--- a/tools/regression/lib/msun/test-fma.c
+++ b/tools/regression/lib/msun/test-fma.c
@@ -362,6 +362,116 @@ test_accuracy(void)
0x1.d87da3aafda40p70L, 0x1.d87da3aafda3fp70L,
0x1.d87da3aafda3fp70L, ALL_STD_EXCEPT, FE_INEXACT);
#endif
+
+ /* ilogb(x*y) - ilogb(z) = 0 */
+ testrnd(fmaf, 0x1.31ad02p+100, 0x1.2fbf7ap-42, -0x1.c3e106p+58,
+ -0x1.64c27cp+56, -0x1.64c27ap+56, -0x1.64c27cp+56,
+ -0x1.64c27ap+56, ALL_STD_EXCEPT, FE_INEXACT);
+ testrnd(fma, 0x1.31ad012ede8aap+100, 0x1.2fbf79c839067p-42,
+ -0x1.c3e106929056ep+58, -0x1.64c282b970a5fp+56,
+ -0x1.64c282b970a5ep+56, -0x1.64c282b970a5fp+56,
+ -0x1.64c282b970a5ep+56, ALL_STD_EXCEPT, FE_INEXACT);
+#if LDBL_MANT_DIG == 113
+ testrnd(fmal, 0x1.31ad012ede8aa282fa1c19376d16p+100L,
+ 0x1.2fbf79c839066f0f5c68f6d2e814p-42L,
+ -0x1.c3e106929056ec19de72bfe64215p+58L,
+ -0x1.64c282b970a612598fc025ca8cddp+56L,
+ -0x1.64c282b970a612598fc025ca8cddp+56L,
+ -0x1.64c282b970a612598fc025ca8cdep+56L,
+ -0x1.64c282b970a612598fc025ca8cddp+56L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+#elif LDBL_MANT_DIG == 64
+ testrnd(fmal, 0x1.31ad012ede8aa4eap+100L, 0x1.2fbf79c839066aeap-42L,
+ -0x1.c3e106929056e61p+58L, -0x1.64c282b970a60298p+56L,
+ -0x1.64c282b970a60298p+56L, -0x1.64c282b970a6029ap+56L,
+ -0x1.64c282b970a60298p+56L, ALL_STD_EXCEPT, FE_INEXACT);
+#elif LDBL_MANT_DIG == 53
+ testrnd(fmal, 0x1.31ad012ede8aap+100L, 0x1.2fbf79c839067p-42L,
+ -0x1.c3e106929056ep+58L, -0x1.64c282b970a5fp+56L,
+ -0x1.64c282b970a5ep+56L, -0x1.64c282b970a5fp+56L,
+ -0x1.64c282b970a5ep+56L, ALL_STD_EXCEPT, FE_INEXACT);
+#endif
+
+ /* x*y (rounded) ~= -z */
+ /* XXX spurious inexact exceptions */
+ testrnd(fmaf, 0x1.bbffeep-30, -0x1.1d164cp-74, 0x1.ee7296p-104,
+ -0x1.c46ea8p-128, -0x1.c46ea8p-128, -0x1.c46ea8p-128,
+ -0x1.c46ea8p-128, ALL_STD_EXCEPT & ~FE_INEXACT, 0);
+ testrnd(fma, 0x1.bbffeea6fc7d6p-30, 0x1.1d164c6cbf078p-74,
+ -0x1.ee72993aff948p-104, -0x1.71f72ac7d9d8p-159,
+ -0x1.71f72ac7d9d8p-159, -0x1.71f72ac7d9d8p-159,
+ -0x1.71f72ac7d9d8p-159, ALL_STD_EXCEPT & ~FE_INEXACT, 0);
+#if LDBL_MANT_DIG == 113
+ testrnd(fmal, 0x1.bbffeea6fc7d65927d147f437675p-30L,
+ 0x1.1d164c6cbf078b7a22607d1cd6a2p-74L,
+ -0x1.ee72993aff94973876031bec0944p-104L,
+ 0x1.64e086175b3a2adc36e607058814p-217L,
+ 0x1.64e086175b3a2adc36e607058814p-217L,
+ 0x1.64e086175b3a2adc36e607058814p-217L,
+ 0x1.64e086175b3a2adc36e607058814p-217L,
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0);
+#elif LDBL_MANT_DIG == 64
+ testrnd(fmal, 0x1.bbffeea6fc7d6592p-30L, 0x1.1d164c6cbf078b7ap-74L,
+ -0x1.ee72993aff949736p-104L, 0x1.af190e7a1ee6ad94p-168L,
+ 0x1.af190e7a1ee6ad94p-168L, 0x1.af190e7a1ee6ad94p-168L,
+ 0x1.af190e7a1ee6ad94p-168L, ALL_STD_EXCEPT & ~FE_INEXACT, 0);
+#elif LDBL_MANT_DIG == 53
+ testrnd(fmal, 0x1.bbffeea6fc7d6p-30L, 0x1.1d164c6cbf078p-74L,
+ -0x1.ee72993aff948p-104L, -0x1.71f72ac7d9d8p-159L,
+ -0x1.71f72ac7d9d8p-159L, -0x1.71f72ac7d9d8p-159L,
+ -0x1.71f72ac7d9d8p-159L, ALL_STD_EXCEPT & ~FE_INEXACT, 0);
+#endif
+}
+
+static void
+test_double_rounding(void)
+{
+
+ /*
+ * a = 0x1.8000000000001p0
+ * b = 0x1.8000000000001p0
+ * c = -0x0.0000000000000000000000000080...1p+1
+ * a * b = 0x1.2000000000001800000000000080p+1
+ *
+ * The correct behavior is to round DOWN to 0x1.2000000000001p+1 in
+ * round-to-nearest mode. An implementation that computes a*b+c in
+ * double+double precision, however, will get 0x1.20000000000018p+1,
+ * and then round UP.
+ */
+ fesetround(FE_TONEAREST);
+ test(fma, 0x1.8000000000001p0, 0x1.8000000000001p0,
+ -0x1.0000000000001p-104, 0x1.2000000000001p+1,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ fesetround(FE_DOWNWARD);
+ test(fma, 0x1.8000000000001p0, 0x1.8000000000001p0,
+ -0x1.0000000000001p-104, 0x1.2000000000001p+1,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ fesetround(FE_UPWARD);
+ test(fma, 0x1.8000000000001p0, 0x1.8000000000001p0,
+ -0x1.0000000000001p-104, 0x1.2000000000002p+1,
+ ALL_STD_EXCEPT, FE_INEXACT);
+
+ fesetround(FE_TONEAREST);
+ test(fmaf, 0x1.800002p+0, 0x1.800002p+0, -0x1.000002p-46, 0x1.200002p+1,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ fesetround(FE_DOWNWARD);
+ test(fmaf, 0x1.800002p+0, 0x1.800002p+0, -0x1.000002p-46, 0x1.200002p+1,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ fesetround(FE_UPWARD);
+ test(fmaf, 0x1.800002p+0, 0x1.800002p+0, -0x1.000002p-46, 0x1.200004p+1,
+ ALL_STD_EXCEPT, FE_INEXACT);
+
+ fesetround(FE_TONEAREST);
+#if LDBL_MANT_DIG == 64
+ test(fmal, 0x1.4p+0L, 0x1.0000000000000004p+0L, 0x1p-128L,
+ 0x1.4000000000000006p+0L, ALL_STD_EXCEPT, FE_INEXACT);
+#elif LDBL_MANT_DIG == 113
+ test(fmal, 0x1.8000000000000000000000000001p+0L,
+ 0x1.8000000000000000000000000001p+0L,
+ -0x1.0000000000000000000000000001p-224L,
+ 0x1.2000000000000000000000000001p+1L, ALL_STD_EXCEPT, FE_INEXACT);
+#endif
+
}
int
@@ -370,7 +480,7 @@ main(int argc, char *argv[])
int rmodes[] = { FE_TONEAREST, FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO };
int i;
- printf("1..18\n");
+ printf("1..19\n");
for (i = 0; i < 4; i++) {
fesetround(rmodes[i]);
@@ -404,6 +514,9 @@ main(int argc, char *argv[])
test_accuracy();
printf("ok 18 - fma accuracy\n");
+ test_double_rounding();
+ printf("ok 19 - fma double rounding\n");
+
/*
* TODO:
* - Tests for subnormals
diff --git a/tools/regression/lib/msun/test-logarithm.c b/tools/regression/lib/msun/test-logarithm.c
index 52f562c..258c514 100644
--- a/tools/regression/lib/msun/test-logarithm.c
+++ b/tools/regression/lib/msun/test-logarithm.c
@@ -97,7 +97,7 @@ void
run_generic_tests(void)
{
- /* exp(1) == 0, no exceptions raised */
+ /* log(1) == 0, no exceptions raised */
testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
testall1(-0.0, -0.0, ALL_STD_EXCEPT, 0);
@@ -142,11 +142,35 @@ run_log2_tests(void)
}
}
+void
+run_roundingmode_tests(void)
+{
+
+ /*
+ * Corner cases in other rounding modes.
+ */
+ fesetround(FE_DOWNWARD);
+ /* These are still positive per IEEE 754R */
+ testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
+ fesetround(FE_TOWARDZERO);
+ testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
+
+ fesetround(FE_UPWARD);
+ testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
+ /* log1p(-0.0) == -0.0 even when rounding upwards */
+ testall1(-0.0, -0.0, ALL_STD_EXCEPT, 0);
+
+ fesetround(FE_TONEAREST);
+}
+
int
main(int argc, char *argv[])
{
- printf("1..2\n");
+ printf("1..3\n");
run_generic_tests();
printf("ok 1 - logarithm\n");
@@ -154,5 +178,8 @@ main(int argc, char *argv[])
run_log2_tests();
printf("ok 2 - logarithm\n");
+ run_roundingmode_tests();
+ printf("ok 3 - logarithm\n");
+
return (0);
}
diff --git a/tools/regression/lib/msun/test-nearbyint.c b/tools/regression/lib/msun/test-nearbyint.c
index 630ddb9..7251acb 100644
--- a/tools/regression/lib/msun/test-nearbyint.c
+++ b/tools/regression/lib/msun/test-nearbyint.c
@@ -30,7 +30,6 @@
* TODO:
* - adapt tests for rint(3)
* - tests for harder values (more mantissa bits than float)
- * - tests in other rounding modes
*/
#include <sys/cdefs.h>
@@ -44,6 +43,27 @@ __FBSDID("$FreeBSD$");
#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
FE_OVERFLOW | FE_UNDERFLOW)
+static int testnum;
+
+static const int rmodes[] = {
+ FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO,
+};
+
+static const struct {
+ float in;
+ float out[3]; /* one answer per rounding mode except towardzero */
+} tests[] = {
+/* input output (expected) */
+ { 0.0, { 0.0, 0.0, 0.0 }},
+ { 0.5, { 0.0, 0.0, 1.0 }},
+ { M_PI, { 3.0, 3.0, 4.0 }},
+ { 65536.5, { 65536, 65536, 65537 }},
+ { INFINITY, { INFINITY, INFINITY, INFINITY }},
+ { NAN, { NAN, NAN, NAN }},
+};
+
+static const int ntests = sizeof(tests) / sizeof(tests[0]);
+
/*
* Compare d1 and d2 using special rules: NaN == NaN and +0 != -0.
* Fail an assertion if they differ.
@@ -57,44 +77,106 @@ fpequal(long double d1, long double d2)
return (copysignl(1.0, d1) == copysignl(1.0, d2));
}
-static void testit(int testnum, float in, float out)
+/* Get the appropriate result for the current rounding mode. */
+static float
+get_output(int testindex, int rmodeindex, int negative)
+{
+ double out;
+
+ if (negative) { /* swap downwards and upwards if input is negative */
+ if (rmodeindex == 1)
+ rmodeindex = 2;
+ else if (rmodeindex == 2)
+ rmodeindex = 1;
+ }
+ if (rmodeindex == 3) /* FE_TOWARDZERO uses the value for downwards */
+ rmodeindex = 1;
+ out = tests[testindex].out[rmodeindex];
+ return (negative ? -out : out);
+}
+
+static void
+test_nearby(int testindex)
{
+ float in, out;
+ int i;
- feclearexcept(ALL_STD_EXCEPT);
- assert(fpequal(out, nearbyintf(in)));
- assert(fpequal(-out, nearbyintf(-in)));
- assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ for (i = 0; i < sizeof(rmodes) / sizeof(rmodes[0]); i++) {
+ fesetround(rmodes[i]);
+ feclearexcept(ALL_STD_EXCEPT);
- assert(fpequal(out, nearbyint(in)));
- assert(fpequal(-out, nearbyint(-in)));
- assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ in = tests[testindex].in;
+ out = get_output(testindex, i, 0);
+ assert(fpequal(out, nearbyintf(in)));
+ assert(fpequal(out, nearbyint(in)));
+ assert(fpequal(out, nearbyintl(in)));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
- assert(fpequal(out, nearbyintl(in)));
- assert(fpequal(-out, nearbyintl(-in)));
- assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ in = -tests[testindex].in;
+ out = get_output(testindex, i, 1);
+ assert(fpequal(out, nearbyintf(in)));
+ assert(fpequal(out, nearbyint(in)));
+ assert(fpequal(out, nearbyintl(in)));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ }
- printf("ok %d\t\t# nearbyint(%g)\n", testnum, in);
+ printf("ok %d\t\t# nearbyint(+%g)\n", testnum++, in);
}
-static const float tests[] = {
-/* input output (expected) */
- 0.0, 0.0,
- 0.5, 0.0,
- M_PI, 3,
- 65536.5, 65536,
- INFINITY, INFINITY,
- NAN, NAN,
-};
+static void
+test_modf(int testindex)
+{
+ float in, out;
+ float ipartf, ipart_expected;
+ double ipart;
+ long double ipartl;
+ int i;
+
+ for (i = 0; i < sizeof(rmodes) / sizeof(rmodes[0]); i++) {
+ fesetround(rmodes[i]);
+ feclearexcept(ALL_STD_EXCEPT);
+
+ in = tests[testindex].in;
+ ipart_expected = tests[testindex].out[1];
+ out = copysignf(
+ isinf(ipart_expected) ? 0.0 : in - ipart_expected, in);
+ ipartl = ipart = ipartf = 42.0;
+
+ assert(fpequal(out, modff(in, &ipartf)));
+ assert(fpequal(ipart_expected, ipartf));
+ assert(fpequal(out, modf(in, &ipart)));
+ assert(fpequal(ipart_expected, ipart));
+ assert(fpequal(out, modfl(in, &ipartl)));
+ assert(fpequal(ipart_expected, ipartl));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+
+ in = -in;
+ ipart_expected = -ipart_expected;
+ out = -out;
+ ipartl = ipart = ipartf = 42.0;
+ assert(fpequal(out, modff(in, &ipartf)));
+ assert(fpequal(ipart_expected, ipartf));
+ assert(fpequal(out, modf(in, &ipart)));
+ assert(fpequal(ipart_expected, ipart));
+ assert(fpequal(out, modfl(in, &ipartl)));
+ assert(fpequal(ipart_expected, ipartl));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ }
+
+ printf("ok %d\t\t# modf(+%g)\n", testnum++, in);
+}
int
main(int argc, char *argv[])
{
- static const int ntests = sizeof(tests) / sizeof(tests[0]) / 2;
int i;
- printf("1..%d\n", ntests);
- for (i = 0; i < ntests; i++)
- testit(i + 1, tests[i * 2], tests[i * 2 + 1]);
+ printf("1..%d\n", ntests * 2);
+ testnum = 1;
+ for (i = 0; i < ntests; i++) {
+ test_nearby(i);
+ test_modf(i);
+ }
return (0);
}
OpenPOWER on IntegriCloud