Blame src/tanh.c

Packit 80c72f
/* mpc_tanh -- hyperbolic tangent of a complex number.
Packit 80c72f
Packit 80c72f
Copyright (C) 2008, 2009, 2011, 2012 INRIA
Packit 80c72f
Packit 80c72f
This file is part of GNU MPC.
Packit 80c72f
Packit 80c72f
GNU MPC is free software; you can redistribute it and/or modify it under
Packit 80c72f
the terms of the GNU Lesser General Public License as published by the
Packit 80c72f
Free Software Foundation; either version 3 of the License, or (at your
Packit 80c72f
option) any later version.
Packit 80c72f
Packit 80c72f
GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
Packit 80c72f
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
Packit 80c72f
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
Packit 80c72f
more details.
Packit 80c72f
Packit 80c72f
You should have received a copy of the GNU Lesser General Public License
Packit 80c72f
along with this program. If not, see http://www.gnu.org/licenses/ .
Packit 80c72f
*/
Packit 80c72f
Packit 80c72f
#include "mpc-impl.h"
Packit 80c72f
Packit 80c72f
int
Packit 80c72f
mpc_tanh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
Packit 80c72f
{
Packit 80c72f
  /* tanh(op) = -i*tan(i*op) = conj(-i*tan(conj(-i*op))) */
Packit 80c72f
  mpc_t z;
Packit 80c72f
  mpc_t tan_z;
Packit 80c72f
  int inex;
Packit 80c72f
Packit 80c72f
  /* z := conj(-i * op) and rop = conj(-i * tan(z)), in other words, we have
Packit 80c72f
     to switch real and imaginary parts. Let us set them without copying
Packit 80c72f
     significands. */
Packit 80c72f
  mpc_realref (z)[0] = mpc_imagref (op)[0];
Packit 80c72f
  mpc_imagref (z)[0] = mpc_realref (op)[0];
Packit 80c72f
  mpc_realref (tan_z)[0] = mpc_imagref (rop)[0];
Packit 80c72f
  mpc_imagref (tan_z)[0] = mpc_realref (rop)[0];
Packit 80c72f
Packit 80c72f
  inex = mpc_tan (tan_z, z, MPC_RND (MPC_RND_IM (rnd), MPC_RND_RE (rnd)));
Packit 80c72f
Packit 80c72f
  /* tan_z and rop parts share the same significands, copy the rest now. */
Packit 80c72f
  mpc_realref (rop)[0] = mpc_imagref (tan_z)[0];
Packit 80c72f
  mpc_imagref (rop)[0] = mpc_realref (tan_z)[0];
Packit 80c72f
Packit 80c72f
  /* swap inexact flags for real and imaginary parts */
Packit 80c72f
  return MPC_INEX (MPC_INEX_IM (inex), MPC_INEX_RE (inex));
Packit 80c72f
}