Back to index

glibc  2.9
s_ccos.c
Go to the documentation of this file.
00001 /* Complex cosine function.  m68k fpu version
00002    Copyright (C) 1997, 1999 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>.
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 #include "mathimpl.h"
00024 
00025 #ifndef SUFF
00026 #define SUFF
00027 #endif
00028 #ifndef float_type
00029 #define float_type double
00030 #endif
00031 
00032 #define CONCATX(a,b) __CONCAT(a,b)
00033 #define s(name) CONCATX(name,SUFF)
00034 #define m81(func) __m81_u(s(func))
00035 
00036 __complex__ float_type
00037 s(__ccos) (__complex__ float_type x)
00038 {
00039   __complex__ float_type retval;
00040   unsigned long rx_cond = __m81_test (__real__ x);
00041 
00042   if ((rx_cond & (__M81_COND_INF|__M81_COND_NAN)) == 0)
00043     {
00044       /* Real part is finite.  */
00045       float_type sin_rx, cos_rx;
00046 
00047       __asm ("fsincos%.x %2,%1:%0" : "=f" (sin_rx), "=f" (cos_rx)
00048             : "f" (__real__ x));
00049       __real__ retval = cos_rx * m81(__ieee754_cosh) (__imag__ x);
00050       if (rx_cond & __M81_COND_ZERO)
00051        __imag__ retval = (m81(__signbit) (__imag__ x)
00052                         ? __real__ x : -__real__ x);
00053       else
00054        __imag__ retval = -sin_rx * m81(__ieee754_sinh) (__imag__ x);
00055     }
00056   else
00057     {
00058       unsigned long ix_cond = __m81_test (__imag__ x);
00059 
00060       if (ix_cond & __M81_COND_INF)
00061        __real__ retval = s(fabs) (__imag__ x);
00062       else
00063        __real__ retval = __real__ x - __real__ x;
00064       if (ix_cond & __M81_COND_ZERO)
00065        __imag__ retval = __imag__ x;
00066       else
00067        __imag__ retval = __real__ x - __real__ x;
00068     }
00069 
00070   return retval;
00071 }
00072 #define weak_aliasx(a,b) weak_alias(a,b)
00073 weak_aliasx (s(__ccos), s(ccos))