Import Upstream version 0.8.2
[platform/upstream/mpc.git] / src / atanh.c
1 /* mpc_atanh -- inverse hyperbolic tangent of a complex number.
2
3 Copyright (C) 2009 Philippe Th\'eveny, Paul Zimmermann
4
5 This file is part of the MPC Library.
6
7 The MPC Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
11
12 The MPC Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the MPC Library; see the file COPYING.LIB.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
21
22 #include "mpc-impl.h"
23
24 int
25 mpc_atanh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
26 {
27   /* atanh(op) = -i*atan(i*op) */
28   int inex;
29   mpfr_t tmp;
30   mpc_t z, a;
31
32   MPC_RE (z)[0] = MPC_IM (op)[0];
33   MPC_IM (z)[0] = MPC_RE (op)[0];
34   MPFR_CHANGE_SIGN (MPC_RE (z));
35
36   /* Note reversal of precisions due to later multiplication by -i */
37   mpc_init3 (a, MPC_PREC_IM(rop), MPC_PREC_RE(rop));
38
39   inex = mpc_atan (a, z,
40                    RNDC (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
41
42   /* change a to -i*a, i.e., x+i*y to y-i*x */
43   tmp[0] = MPC_RE (a)[0];
44   MPC_RE (a)[0] = MPC_IM (a)[0];
45   MPC_IM (a)[0] = tmp[0];
46   MPFR_CHANGE_SIGN (MPC_IM (a));
47
48   mpc_set (rop, a, rnd);
49
50   mpc_clear (a);
51
52   return MPC_INEX (MPC_INEX_IM (inex), -MPC_INEX_RE (inex));
53 }