Share via


cos, cosf, cosl

計算余弦值。

語法

double cos( double x );
float cosf( float x );
long double cosl( long double x );
#define cos(X) // Requires C11 or higher

float cos( float x );  // C++ only
long double cos( long double x );  // C++ only

參數

x
角度 (弧度)。

傳回值

x 的餘弦函數。 如果 x 大於或等於 263,或小於或等於 -263,則結果中會遺失重要性。

輸入 SEH 例外狀況 _matherr 例外
± QNaN,IND none _DOMAIN
± INF INVALID _DOMAIN

備註

因為 C++ 允許多載,所以您可以呼叫採用並傳回 cosfloat 值的 long double 的多載。 在 C 程式中,除非您使用 < tgmath.h > 宏來呼叫此函式, cos 否則一律會採用 並傳 double 回 。

如果您使用 < tgmath.h >cos() 宏,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的 C 標頭 必要的 C++ 標頭
cos, cosh, cosf <math.h> <cmath > 或 < math.h>
cos() <tgmath.h>

如需相容性詳細資訊,請參閱相容性

範例

請參閱 、 sinlsinf 中的 sin 範例。

另請參閱

數學和浮點支援
acos, acosf, acosl
asin, asinf, asinl
atan, atanf, atanl, atan2, atan2f, atan2l
_matherr
sin, sinf, sinl
tan, tanf, tanl