diff options
-rw-r--r-- | lib/libm/src/s_cacosh.c | 4 | ||||
-rw-r--r-- | lib/libm/src/s_cacoshf.c | 4 | ||||
-rw-r--r-- | regress/lib/libm/complex/Makefile | 7 | ||||
-rw-r--r-- | regress/lib/libm/complex/complex.c | 42 |
4 files changed, 53 insertions, 4 deletions
diff --git a/lib/libm/src/s_cacosh.c b/lib/libm/src/s_cacosh.c index 75af1a35c08..6ed364fdcdb 100644 --- a/lib/libm/src/s_cacosh.c +++ b/lib/libm/src/s_cacosh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_cacosh.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */ +/* $OpenBSD: s_cacosh.c,v 1.7 2015/07/16 13:29:11 martynas Exp $ */ /* * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> * @@ -51,7 +51,7 @@ cacosh(double complex z) { double complex w; - w = I * cacos (z); + w = clog(z + csqrt(z + 1) * csqrt(z - 1)); return (w); } diff --git a/lib/libm/src/s_cacoshf.c b/lib/libm/src/s_cacoshf.c index d81f7843c91..16016be3b33 100644 --- a/lib/libm/src/s_cacoshf.c +++ b/lib/libm/src/s_cacoshf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_cacoshf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */ +/* $OpenBSD: s_cacoshf.c,v 1.2 2015/07/16 13:29:11 martynas Exp $ */ /* * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> * @@ -50,6 +50,6 @@ cacoshf(float complex z) { float complex w; - w = I * cacosf (z); + w = clogf(z + csqrtf(z + 1) * csqrtf(z - 1)); return (w); } 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); +} |