Back to index

glibc  2.9
s_cacoshf.c
Go to the documentation of this file.
00001 /* Return arc hyperbole cosine for float value.
00002    Copyright (C) 1997, 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 <math.h>
00023 
00024 #include "math_private.h"
00025 
00026 __complex__ float
00027 __cacoshf (__complex__ float x)
00028 {
00029   __complex__ float res;
00030   int rcls = fpclassify (__real__ x);
00031   int icls = fpclassify (__imag__ x);
00032 
00033   if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
00034     {
00035       if (icls == FP_INFINITE)
00036        {
00037          __real__ res = HUGE_VALF;
00038 
00039          if (rcls == FP_NAN)
00040            __imag__ res = __nanf ("");
00041          else
00042            __imag__ res = __copysignf ((rcls == FP_INFINITE
00043                                     ? (__real__ x < 0.0
00044                                        ? M_PI - M_PI_4 : M_PI_4)
00045                                     : M_PI_2), __imag__ x);
00046        }
00047       else if (rcls == FP_INFINITE)
00048        {
00049          __real__ res = HUGE_VALF;
00050 
00051          if (icls >= FP_ZERO)
00052            __imag__ res = __copysignf (signbit (__real__ x) ? M_PI : 0.0,
00053                                    __imag__ x);
00054          else
00055            __imag__ res = __nanf ("");
00056        }
00057       else
00058        {
00059          __real__ res = __nanf ("");
00060          __imag__ res = __nanf ("");
00061        }
00062     }
00063   else if (rcls == FP_ZERO && icls == FP_ZERO)
00064     {
00065       __real__ res = 0.0;
00066       __imag__ res = __copysignf (M_PI_2, __imag__ x);
00067     }
00068   else
00069     {
00070 #if 1
00071       __complex__ float y;
00072 
00073       __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
00074       __imag__ y = 2.0 * __real__ x * __imag__ x;
00075 
00076       y = __csqrtf (y);
00077 
00078       if (__real__ x < 0.0)
00079        y = -y;
00080 
00081       __real__ y += __real__ x;
00082       __imag__ y += __imag__ x;
00083 
00084       res = __clogf (y);
00085 #else
00086       float re2 = __real__ x * __real__ x;
00087       float im2 = __imag__ x * __imag__ x;
00088       float sq = re2 - im2 - 1.0;
00089       float ro = __ieee754_sqrtf (sq * sq + 4 * re2 * im2);
00090       float a = __ieee754_sqrtf ((sq + ro) / 2.0);
00091       float b = __ieee754_sqrtf ((-sq + ro) / 2.0);
00092 
00093       __real__ res = 0.5 * __ieee754_logf (re2 + __real__ x * 2 * a
00094                                       + im2 + __imag__ x * 2 * b
00095                                       + ro);
00096       __imag__ res = __ieee754_atan2f (__imag__ x + b, __real__ x + a);
00097 #endif
00098 
00099       /* We have to use the positive branch.  */
00100       if (__real__ res < 0.0)
00101        res = -res;
00102     }
00103 
00104   return res;
00105 }
00106 #ifndef __cacoshf
00107 weak_alias (__cacoshf, cacoshf)
00108 #endif