Back to index

glibc  2.9
s_ctanl.c
Go to the documentation of this file.
00001 /* Complex tangent function 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 __ctanl (__complex__ long double x)
00031 {
00032   __complex__ long double res;
00033 
00034   if (!isfinite (__real__ x) || !isfinite (__imag__ x))
00035     {
00036       if (__isinfl (__imag__ x))
00037        {
00038          __real__ res = __copysignl (0.0, __real__ x);
00039          __imag__ res = __copysignl (1.0, __imag__ x);
00040        }
00041       else if (__real__ 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 (__real__ x))
00052            feraiseexcept (FE_INVALID);
00053 #endif
00054        }
00055     }
00056   else
00057     {
00058       long double sin2rx, cos2rx;
00059       long double den;
00060 
00061       __sincosl (2.0 * __real__ x, &sin2rx, &cos2rx);
00062 
00063       den = cos2rx + __ieee754_coshl (2.0 * __imag__ x);
00064 
00065 
00066       if (den == 0.0)
00067        {
00068          __complex__ long double ez = __cexpl (1.0i * x);
00069          __complex__ long double emz = __cexpl (-1.0i * x);
00070 
00071          res = (ez - emz) / (ez + emz) * -1.0i;
00072        }
00073       else
00074        {
00075          __real__ res = sin2rx / den;
00076          __imag__ res = __ieee754_sinhl (2.0 * __imag__ x) / den;
00077        }
00078       /* __gcc_qmul does not respect -0.0 so we need the following fixup.  */
00079       if ((__real__ res == 0.0) && (__real__ x == 0.0))
00080         __real__ res = __real__ x;
00081 
00082       if ((__real__ res == 0.0) && (__imag__ x == 0.0))
00083         __imag__ res = __imag__ x;
00084     }
00085 
00086   return res;
00087 }
00088 long_double_symbol (libm, __ctanl, ctanl);