Back to index

glibc  2.9
s_ctanhl.c
Go to the documentation of this file.
00001 /* Complex hyperbole tangent for long double.  IBM extended format version.
00002    Copyright (C) 1997,2005,2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <complex.h>
00022 #include <fenv.h>
00023 #include <math.h>
00024 #include <math_ldbl_opt.h>
00025 
00026 #include "math_private.h"
00027 
00028 
00029 __complex__ long double
00030 __ctanhl (__complex__ long double x)
00031 {
00032   __complex__ long double res;
00033 
00034   if (!isfinite (__real__ x) || !isfinite (__imag__ x))
00035     {
00036       if (__isinfl (__real__ x))
00037        {
00038          __real__ res = __copysignl (1.0, __real__ x);
00039          __imag__ res = __copysignl (0.0, __imag__ x);
00040        }
00041       else if (__imag__ x == 0.0)
00042        {
00043          res = x;
00044        }
00045       else
00046        {
00047          __real__ res = __nanl ("");
00048          __imag__ res = __nanl ("");
00049 
00050 #ifdef FE_INVALID
00051          if (__isinfl (__imag__ x))
00052            feraiseexcept (FE_INVALID);
00053 #endif
00054        }
00055     }
00056   else
00057     {
00058       long double sin2ix, cos2ix;
00059       long double den;
00060 
00061       __sincosl (2.0 * __imag__ x, &sin2ix, &cos2ix);
00062 
00063       den = (__ieee754_coshl (2.0 * __real__ x) + cos2ix);
00064 
00065       if (den == 0.0L)
00066        {
00067          __complex__ long double ez = __cexpl (x);
00068          __complex__ long double emz = __cexpl (-x);
00069 
00070          res = (ez - emz) / (ez + emz);
00071        }
00072       else
00073        {
00074          __real__ res = __ieee754_sinhl (2.0 * __real__ x) / den;
00075          __imag__ res = sin2ix / den;
00076        }
00077       /* __gcc_qmul does not respect -0.0 so we need the following fixup.  */
00078       if ((__real__ res == 0.0) && (__real__ x == 0.0))
00079         __real__ res = __real__ x;
00080 
00081       if ((__real__ res == 0.0) && (__imag__ x == 0.0))
00082         __imag__ res = __imag__ x;
00083     }
00084 
00085   return res;
00086 }
00087 long_double_symbol (libm, __ctanhl, ctanhl);