Back to index

glibc  2.9
s_ctan.c
Go to the documentation of this file.
00001 /* Complex tangent function for double.
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__ double
00029 __ctan (__complex__ double x)
00030 {
00031   __complex__ double res;
00032 
00033   if (!isfinite (__real__ x) || !isfinite (__imag__ x))
00034     {
00035       if (__isinf (__imag__ x))
00036        {
00037          __real__ res = __copysign (0.0, __real__ x);
00038          __imag__ res = __copysign (1.0, __imag__ x);
00039        }
00040       else if (__real__ x == 0.0)
00041        {
00042          res = x;
00043        }
00044       else
00045        {
00046          __real__ res = __nan ("");
00047          __imag__ res = __nan ("");
00048 
00049 #ifdef FE_INVALID
00050          if (__isinf (__real__ x))
00051            feraiseexcept (FE_INVALID);
00052 #endif
00053        }
00054     }
00055   else
00056     {
00057       double sin2rx, cos2rx;
00058       double den;
00059 
00060       __sincos (2.0 * __real__ x, &sin2rx, &cos2rx);
00061 
00062       den = cos2rx + __ieee754_cosh (2.0 * __imag__ x);
00063 
00064       if (den == 0.0)
00065        {
00066          __complex__ double ez = __cexp (1.0i * x);
00067          __complex__ double emz = __cexp (-1.0i * x);
00068 
00069          res = (ez - emz) / (ez + emz) * -1.0i;
00070        }
00071       else
00072        {
00073          __real__ res = sin2rx / den;
00074          __imag__ res = __ieee754_sinh (2.0 * __imag__ x) / den;
00075        }
00076     }
00077 
00078   return res;
00079 }
00080 weak_alias (__ctan, ctan)
00081 #ifdef NO_LONG_DOUBLE
00082 strong_alias (__ctan, __ctanl)
00083 weak_alias (__ctan, ctanl)
00084 #endif