Back to index

glibc  2.9
s_ctanhf.c
Go to the documentation of this file.
00001 /* Complex hyperbole tangent for float.
00002    Copyright (C) 1997, 2005 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 
00025 #include "math_private.h"
00026 
00027 
00028 __complex__ float
00029 __ctanhf (__complex__ float x)
00030 {
00031   __complex__ float res;
00032 
00033   if (!isfinite (__real__ x) || !isfinite (__imag__ x))
00034     {
00035       if (__isinff (__real__ x))
00036        {
00037          __real__ res = __copysignf (1.0, __real__ x);
00038          __imag__ res = __copysignf (0.0, __imag__ x);
00039        }
00040       else if (__imag__ x == 0.0)
00041        {
00042          res = x;
00043        }
00044       else
00045        {
00046          __real__ res = __nanf ("");
00047          __imag__ res = __nanf ("");
00048 
00049 #ifdef FE_INVALID
00050          if (__isinff (__imag__ x))
00051            feraiseexcept (FE_INVALID);
00052 #endif
00053        }
00054     }
00055   else
00056     {
00057       float sin2ix, cos2ix;
00058       float den;
00059 
00060       __sincosf (2.0 * __imag__ x, &sin2ix, &cos2ix);
00061 
00062       den = (__ieee754_coshf (2.0 * __real__ x) + cos2ix);
00063 
00064       if (den == 0.0f)
00065        {
00066          __complex__ float ez = __cexpf (x);
00067          __complex__ float emz = __cexpf (-x);
00068 
00069          res = (ez - emz) / (ez + emz);
00070        }
00071       else
00072        {
00073          __real__ res = __ieee754_sinhf (2.0 * __real__ x) / den;
00074          __imag__ res = sin2ix / den;
00075        }
00076     }
00077 
00078   return res;
00079 }
00080 #ifndef __ctanhf
00081 weak_alias (__ctanhf, ctanhf)
00082 #endif