From ea0af5971c3e88793a5db1a4582d2059cabd2ec6 Mon Sep 17 00:00:00 2001 From: zimmerma Date: Fri, 20 Nov 2009 13:28:30 +0000 Subject: fixed bug reported by Geoff Bailey (acosh, asinh and atanh swap the precisions of their inputs) git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@723 211d60ee-9f03-0410-a15a-8952a2c7a4e4 --- src/asinh.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/asinh.c') diff --git a/src/asinh.c b/src/asinh.c index 4b67f9e..09c2ac7 100644 --- a/src/asinh.c +++ b/src/asinh.c @@ -1,6 +1,6 @@ /* mpc_asinh -- inverse hyperbolic sine of a complex number. -Copyright (C) 2009 Philippe Th\'eveny +Copyright (C) 2009 Philippe Th\'eveny, Paul Zimmermann This file is part of the MPC Library. @@ -26,21 +26,31 @@ mpc_asinh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) { /* asinh(op) = -i*asin(i*op) */ int inex; - mpc_t z; + mpc_t z, a; mpfr_t tmp; + /* z = i*op */ MPC_RE (z)[0] = MPC_IM (op)[0]; MPC_IM (z)[0] = MPC_RE (op)[0]; MPFR_CHANGE_SIGN (MPC_RE (z)); - inex = mpc_asin (rop, z, + /* Note reversal of precisions due to later multiplication by -i */ + mpc_init3 (a, MPC_PREC_IM(rop), MPC_PREC_RE(rop)); + + inex = mpc_asin (a, z, RNDC (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd))); - /* change rop to -i*rop */ - tmp[0] = MPC_RE (rop)[0]; - MPC_RE (rop)[0] = MPC_IM (rop)[0]; - MPC_IM (rop)[0] = tmp[0]; - MPFR_CHANGE_SIGN (MPC_IM (rop)); + /* if a = asin(i*op) = x+i*y, and we want y-i*x */ + + /* change a to -i*a */ + tmp[0] = MPC_RE (a)[0]; + MPC_RE (a)[0] = MPC_IM (a)[0]; + MPC_IM (a)[0] = tmp[0]; + MPFR_CHANGE_SIGN (MPC_IM (a)); + + mpc_set (rop, a, MPC_RNDNN); /* exact */ + + mpc_clear (a); return MPC_INEX (MPC_INEX_IM (inex), -MPC_INEX_RE (inex)); } -- cgit v1.2.1