共用方式為


cos、cosf、cosl、cosh、coshf、coshl

計算餘弦函數 (cos、 cosf或 cosl),或者 Hyperbolic Cosine (cosh、 coshf或 coshl)。

double cos( 
   double x 
);
float cos(
   float x 
);  // C++ only
long double cos(
   long double x
);  // C++ only
float cosf( 
   float x 
);
long double cosl(
   long double x
);
double cosh( 
   double x 
);
float cosh(
   float x 
);  // C++ only
long double cosh(
   long double x
);  // C++ only
float coshf(
   float x 
);
long double coshl(
   long double x
);

參數

  • x
    角度 (以弧度為單位)。

傳回值

餘弦值或 x的雙曲線餘弦函數。 如果 x 大於或等於 263 或小於或等於,則會傳回– 263 顯著性位元會遺失對呼叫的結果為 cos的 cosf,或者 cosl 隨即出現。

根據預設,若在 cosh、 coshf或 coshl呼叫中結果太大,函式傳回 HUGE_VAL ,並將 errno 設定為 ERANGE。

輸入

SEH 例外狀況

Matherr 例外狀況

± QNAN,IND

_DOMAIN

± ∞ (cosf, cos, cosl)

INVALID

_DOMAIN

x ≥ 7.104760e+002 (cosh、 coshf, coshl)。

INEXACT+OVERFLOW

OVERFLOW

備註

因為 C++ 允許多載,您可以呼叫會接受並傳回 float 或 long double 值的 cos 和 cosh 之多載。 在 C 程式中,cos 和 cosh 永遠接受並傳回 double。

需求

常式

必要的標頭

cos, cosh, cosf, coshf, cosl, coshl

<math.h>

如需其他相容性資訊,請參閱 相容性

範例

請參閱 sin、sinf、sinl、sinh、sinhf、sinhl 中的範例。

.NET Framework 對等用法

請參閱

參考

浮點支援

acos、acosf、acosl

asin、asinf、asinl

atan、atanf、atanl、atan2、atan2f、atan2l

_matherr

sin、sinf、sinl、sinh、sinhf、sinhl

tan、tanf、tanl、tanh、tanhf、tanhl

_CIcos