summaryrefslogtreecommitdiffstats
path: root/regress/lib/libm
diff options
context:
space:
mode:
authormartynas <martynas@openbsd.org>2015-07-16 13:29:11 +0000
committermartynas <martynas@openbsd.org>2015-07-16 13:29:11 +0000
commitbbd647e6a3b95d13fe73ae9d2afe81311675daef (patch)
treebe02757c11f857b99bcc5011838f13665fb55a23 /regress/lib/libm
parentMove grab/release of the kernel_lock for softintrs from the ASM stubs to (diff)
downloadwireguard-openbsd-bbd647e6a3b95d13fe73ae9d2afe81311675daef.tar.xz
wireguard-openbsd-bbd647e6a3b95d13fe73ae9d2afe81311675daef.zip
Signs of cacosh/cacoshf were not always correct (e.g., -1.1 -1.1i),
as found by fortran regression tests. Also added some complex regression tests for cacosh, casinh, catanh. Reported by John Marino @ DragonFlyBSD.
Diffstat (limited to 'regress/lib/libm')
-rw-r--r--regress/lib/libm/complex/Makefile7
-rw-r--r--regress/lib/libm/complex/complex.c42
2 files changed, 49 insertions, 0 deletions
diff --git a/regress/lib/libm/complex/Makefile b/regress/lib/libm/complex/Makefile
new file mode 100644
index 00000000000..c3648851c8a
--- /dev/null
+++ b/regress/lib/libm/complex/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1 2015/07/16 13:29:11 martynas Exp $
+
+PROG=complex
+LDADD=-lm
+DPADD=${LIBM}
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libm/complex/complex.c b/regress/lib/libm/complex/complex.c
new file mode 100644
index 00000000000..133cfafe017
--- /dev/null
+++ b/regress/lib/libm/complex/complex.c
@@ -0,0 +1,42 @@
+/* $OpenBSD: complex.c,v 1.1 2015/07/16 13:29:11 martynas Exp $ */
+
+/*
+ * Written by Martynas Venckus. Public domain
+ */
+
+#include <assert.h>
+#include <complex.h>
+#include <math.h>
+
+#define PREC 1000
+#define test(f, r, i) ( \
+ floor((__real__ (f)) * PREC) == floor((r) * PREC) && \
+ floor((__imag__ (f)) * PREC) == floor((i) * PREC) \
+)
+#define testf(f, r, i) ( \
+ floorf((__real__ (f)) * PREC) == floorf((r) * PREC) && \
+ floorf((__imag__ (f)) * PREC) == floorf((i) * PREC) \
+)
+
+int
+main(int argc, char *argv[])
+{
+ double complex r, z4 = -1.1 - 1.1 * I;
+ float complex rf, z4f = -1.1 - 1.1 * I;
+
+ r = cacosh(z4);
+ assert(test(r, 1.150127, -2.256295));
+ r = casinh(z4);
+ assert(test(r, -1.150127, -0.685498));
+ r = catanh(z4);
+ assert(test(r, -0.381870, -1.071985));
+
+ rf = cacoshf(z4f);
+ assert(testf(rf, 1.150127, -2.256295));
+ rf = casinhf(z4f);
+ assert(testf(rf, -1.150127, -0.685498));
+ rf = catanhf(z4f);
+ assert(testf(rf, -0.381870, -1.071985));
+
+ return (0);
+}