1132624Smarcel/* Return cosine of complex double value. 2132624Smarcel Copyright (C) 1997 Free Software Foundation, Inc. 3132624Smarcel This file is part of the GNU C Library. 4132624Smarcel Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. 5132624Smarcel 6132624Smarcel The GNU C Library is free software; you can redistribute it and/or 7132624Smarcel modify it under the terms of the GNU Lesser General Public 8132624Smarcel License as published by the Free Software Foundation; either 9132624Smarcel version 2.1 of the License, or (at your option) any later version. 10132624Smarcel 11132624Smarcel The GNU C Library is distributed in the hope that it will be useful, 12132624Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 13132624Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14132624Smarcel Lesser General Public License for more details. 15132624Smarcel 16132624Smarcel You should have received a copy of the GNU Lesser General Public 17132624Smarcel License along with the GNU C Library; if not, write to the Free 18132624Smarcel Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19132624Smarcel 02111-1307 USA. */ 20132624Smarcel 21132624Smarcel#include <complex.h> 22132624Smarcel#include <fenv.h> 23132624Smarcel#include <math.h> 24132624Smarcel 25132624Smarcel 26132624Smarcel__complex__ double 27132624Smarcel__ccos (__complex__ double x) 28132624Smarcel{ 29132624Smarcel __complex__ double res; 30132624Smarcel 31132624Smarcel if (!isfinite (__real__ x) || __isnan (__imag__ x)) 32132624Smarcel { 33132624Smarcel if (__real__ x == 0.0 || __imag__ x == 0.0) 34132624Smarcel { 35132624Smarcel __real__ res = nan (""); 36132624Smarcel __imag__ res = 0.0; 37132624Smarcel 38132624Smarcel#ifdef FE_INVALID 39132624Smarcel if (__isinf (__real__ x)) 40132624Smarcel feraiseexcept (FE_INVALID); 41132624Smarcel#endif 42132624Smarcel } 43133739Smarcel else if (__isinf (__imag__ x)) 44132624Smarcel { 45132624Smarcel __real__ res = HUGE_VAL; 46132624Smarcel __imag__ res = nan (""); 47132624Smarcel 48132624Smarcel#ifdef FE_INVALID 49132624Smarcel if (__isinf (__real__ x)) 50132624Smarcel feraiseexcept (FE_INVALID); 51132624Smarcel#endif 52149954Smarcel } 53132624Smarcel else 54132624Smarcel { 55132624Smarcel __real__ res = nan (""); 56132624Smarcel __imag__ res = nan (""); 57178670Sjhb 58132624Smarcel#ifdef FE_INVALID 59132624Smarcel if (isfinite (__imag__ x)) 60178670Sjhb feraiseexcept (FE_INVALID); 61142151Skan#endif 62142151Skan } 63177715Sjhb } 64132624Smarcel else 65149954Smarcel { 66149954Smarcel __complex__ double y; 67132624Smarcel 68132624Smarcel __real__ y = -__imag__ x; 69132624Smarcel __imag__ y = __real__ x; 70175770Sjhb 71132624Smarcel res = __ccosh (y); 72132624Smarcel } 73132624Smarcel 74178670Sjhb return res; 75133739Smarcel} 76132624Smarcelweak_alias (__ccos, ccos) 77178670Sjhb#ifdef NO_LONG_DOUBLE 78132624Smarcelstrong_alias (__ccos, __ccosl) 79132624Smarcelweak_alias (__ccos, ccosl) 80132624Smarcel#endif 81132624Smarcel