Back to index

glibc  2.9
s_ccoshl.c
Go to the documentation of this file.
00001 /* Complex cosine hyperbole function for long double.
00002    Copyright (C) 1997 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__ long double
00029 __ccoshl (__complex__ long double x)
00030 {
00031   __complex__ long double retval;
00032   int rcls = fpclassify (__real__ x);
00033   int icls = fpclassify (__imag__ x);
00034 
00035   if (rcls >= FP_ZERO)
00036     {
00037       /* Real part is finite.  */
00038       if (icls >= FP_ZERO)
00039        {
00040          /* Imaginary part is finite.  */
00041          long double sinh_val = __ieee754_sinhl (__real__ x);
00042          long double cosh_val = __ieee754_coshl (__real__ x);
00043          long double sinix, cosix;
00044 
00045          __sincosl (__imag__ x, &sinix, &cosix);
00046 
00047          __real__ retval = cosh_val * cosix;
00048          __imag__ retval = sinh_val * sinix;
00049        }
00050       else
00051        {
00052          __imag__ retval = __real__ x == 0.0 ? 0.0 : __nanl ("");
00053          __real__ retval = __nanl ("") + __nanl ("");
00054 
00055 #ifdef FE_INVALID
00056          if (icls == FP_INFINITE)
00057            feraiseexcept (FE_INVALID);
00058 #endif
00059        }
00060     }
00061   else if (rcls == FP_INFINITE)
00062     {
00063       /* Real part is infinite.  */
00064       if (icls == FP_ZERO)
00065        {
00066          /* Imaginary part is 0.0.  */
00067          __real__ retval = HUGE_VALL;
00068          __imag__ retval = __imag__ x * __copysignl (1.0, __real__ x);
00069        }
00070       else if (icls > FP_ZERO)
00071        {
00072          /* Imaginary part is finite.  */
00073          long double sinix, cosix;
00074 
00075          __sincosl (__imag__ x, &sinix, &cosix);
00076 
00077          __real__ retval = __copysignl (HUGE_VALL, cosix);
00078          __imag__ retval = (__copysignl (HUGE_VALL, sinix)
00079                           * __copysignl (1.0, __real__ x));
00080        }
00081       else
00082        {
00083          /* The addition raises the invalid exception.  */
00084          __real__ retval = HUGE_VALL;
00085          __imag__ retval = __nanl ("") + __nanl ("");
00086 
00087 #ifdef FE_INVALID
00088          if (icls == FP_INFINITE)
00089            feraiseexcept (FE_INVALID);
00090 #endif
00091        }
00092     }
00093   else
00094     {
00095       __real__ retval = __nanl ("");
00096       __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nanl ("");
00097     }
00098 
00099   return retval;
00100 }
00101 weak_alias (__ccoshl, ccoshl)