Back to index

glibc  2.9
s_csinhl.c
Go to the documentation of this file.
00001 /* Complex sine 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 __csinhl (__complex__ long double x)
00030 {
00031   __complex__ long double retval;
00032   int negate = signbit (__real__ x);
00033   int rcls = fpclassify (__real__ x);
00034   int icls = fpclassify (__imag__ x);
00035 
00036   __real__ x = fabsl (__real__ x);
00037 
00038   if (rcls >= FP_ZERO)
00039     {
00040       /* Real part is finite.  */
00041       if (icls >= FP_ZERO)
00042        {
00043          /* Imaginary part is finite.  */
00044          long double sinh_val = __ieee754_sinhl (__real__ x);
00045          long double cosh_val = __ieee754_coshl (__real__ x);
00046          long double sinix, cosix;
00047 
00048          __sincosl (__imag__ x, &sinix, &cosix);
00049 
00050          __real__ retval = sinh_val * cosix;
00051          __imag__ retval = cosh_val * sinix;
00052 
00053          if (negate)
00054            __real__ retval = -__real__ retval;
00055        }
00056       else
00057        {
00058          if (rcls == FP_ZERO)
00059            {
00060              /* Real part is 0.0.  */
00061              __real__ retval = __copysignl (0.0, negate ? -1.0 : 1.0);
00062              __imag__ retval = __nanl ("") + __nanl ("");
00063 
00064 #ifdef FE_INVALID
00065              if (icls == FP_INFINITE)
00066               feraiseexcept (FE_INVALID);
00067 #endif
00068            }
00069          else
00070            {
00071              __real__ retval = __nanl ("");
00072              __imag__ retval = __nanl ("");
00073 
00074 #ifdef FE_INVALID
00075              feraiseexcept (FE_INVALID);
00076 #endif
00077            }
00078        }
00079     }
00080   else if (rcls == FP_INFINITE)
00081     {
00082       /* Real part is infinite.  */
00083       if (icls == FP_ZERO)
00084        {
00085          /* Imaginary part is 0.0.  */
00086          __real__ retval = negate ? -HUGE_VALL : HUGE_VALL;
00087          __imag__ retval = __imag__ x;
00088        }
00089       else if (icls > FP_ZERO)
00090        {
00091          /* Imaginary part is finite.  */
00092          long double sinix, cosix;
00093 
00094          __sincosl (__imag__ x, &sinix, &cosix);
00095 
00096          __real__ retval = __copysignl (HUGE_VALL, cosix);
00097          __imag__ retval = __copysignl (HUGE_VALL, sinix);
00098 
00099          if (negate)
00100            __real__ retval = -__real__ retval;
00101        }
00102       else
00103        {
00104          /* The addition raises the invalid exception.  */
00105          __real__ retval = HUGE_VALL;
00106          __imag__ retval = __nanl ("") + __nanl ("");
00107 
00108 #ifdef FE_INVALID
00109          if (icls == FP_INFINITE)
00110            feraiseexcept (FE_INVALID);
00111 #endif
00112        }
00113     }
00114   else
00115     {
00116       __real__ retval = __nanl ("");
00117       __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nanl ("");
00118     }
00119 
00120   return retval;
00121 }
00122 weak_alias (__csinhl, csinhl)