usr.sbin/makefs/hammer2: Remove redundant hammer2_inode_modify()
[dragonfly.git] / contrib / mpc / src / acosh.c
blob782f5550c2f12c379388091ff5d8840dd367c28a
1 /* mpc_acosh -- inverse hyperbolic cosine of a complex number.
3 Copyright (C) 2009, 2011, 2012 INRIA
5 This file is part of GNU MPC.
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
21 #include "mpc-impl.h"
23 int
24 mpc_acosh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
26 /* acosh(z) =
27 NaN + i*NaN, if z=0+i*NaN
28 -i*acos(z), if sign(Im(z)) = -
29 i*acos(z), if sign(Im(z)) = +
30 http://functions.wolfram.com/ElementaryFunctions/ArcCosh/27/02/03/01/01/
32 mpc_t a;
33 mpfr_t tmp;
34 int inex;
36 if (mpfr_zero_p (mpc_realref (op)) && mpfr_nan_p (mpc_imagref (op)))
38 mpfr_set_nan (mpc_realref (rop));
39 mpfr_set_nan (mpc_imagref (rop));
40 return 0;
43 /* Note reversal of precisions due to later multiplication by i or -i */
44 mpc_init3 (a, MPC_PREC_IM(rop), MPC_PREC_RE(rop));
46 if (mpfr_signbit (mpc_imagref (op)))
48 inex = mpc_acos (a, op,
49 MPC_RND (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
51 /* change a to -i*a, i.e., -y+i*x to x+i*y */
52 tmp[0] = mpc_realref (a)[0];
53 mpc_realref (a)[0] = mpc_imagref (a)[0];
54 mpc_imagref (a)[0] = tmp[0];
55 MPFR_CHANGE_SIGN (mpc_imagref (a));
56 inex = MPC_INEX (MPC_INEX_IM (inex), -MPC_INEX_RE (inex));
58 else
60 inex = mpc_acos (a, op,
61 MPC_RND (MPC_RND_IM (rnd), INV_RND(MPC_RND_RE (rnd))));
63 /* change a to i*a, i.e., y-i*x to x+i*y */
64 tmp[0] = mpc_realref (a)[0];
65 mpc_realref (a)[0] = mpc_imagref (a)[0];
66 mpc_imagref (a)[0] = tmp[0];
67 MPFR_CHANGE_SIGN (mpc_realref (a));
68 inex = MPC_INEX (-MPC_INEX_IM (inex), MPC_INEX_RE (inex));
71 mpc_set (rop, a, rnd);
73 mpc_clear (a);
75 return inex;