Back to index

glibc  2.9
s_casinh.c
Go to the documentation of this file.
00001 /* Return arc hyperbole sine for double value.
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 <math.h>
00023 
00024 
00025 __complex__ double
00026 __casinh (__complex__ double x)
00027 {
00028   __complex__ double res;
00029   int rcls = fpclassify (__real__ x);
00030   int icls = fpclassify (__imag__ x);
00031 
00032   if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
00033     {
00034       if (icls == FP_INFINITE)
00035        {
00036          __real__ res = __copysign (HUGE_VAL, __real__ x);
00037 
00038          if (rcls == FP_NAN)
00039            __imag__ res = __nan ("");
00040          else
00041            __imag__ res = __copysign (rcls >= FP_ZERO ? M_PI_2 : M_PI_4,
00042                                    __imag__ x);
00043        }
00044       else if (rcls <= FP_INFINITE)
00045        {
00046          __real__ res = __real__ x;
00047          if ((rcls == FP_INFINITE && icls >= FP_ZERO)
00048              || (rcls == FP_NAN && icls == FP_ZERO))
00049            __imag__ res = __copysign (0.0, __imag__ x);
00050          else
00051            __imag__ res = __nan ("");
00052        }
00053       else
00054        {
00055          __real__ res = __nan ("");
00056          __imag__ res = __nan ("");
00057        }
00058     }
00059   else if (rcls == FP_ZERO && icls == FP_ZERO)
00060     {
00061       res = x;
00062     }
00063   else
00064     {
00065       __complex__ double y;
00066 
00067       __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0;
00068       __imag__ y = 2.0 * __real__ x * __imag__ x;
00069 
00070       y = __csqrt (y);
00071 
00072       __real__ y += __real__ x;
00073       __imag__ y += __imag__ x;
00074 
00075       res = __clog (y);
00076     }
00077 
00078   return res;
00079 }
00080 weak_alias (__casinh, casinh)
00081 #ifdef NO_LONG_DOUBLE
00082 strong_alias (__casinh, __casinhl)
00083 weak_alias (__casinh, casinhl)
00084 #endif