sin
, sinf
, sinl
計算浮點值的正弦值。
語法
double sin(double x);
float sinf(float x);
long double sinl(long double x);
#define sin(x) // Requires C11 or higher
float sin(float x); // C++ only
long double sin(long double x); // C++ only
參數
x
角度 (弧度)。
傳回值
sin
函式會傳回 x
的正弦值。 如果 x
大於或等於 263,或小於或等於 -263,則結果中會遺失重要性。
輸入 | SEH 例外狀況 | _matherr 例外 |
---|---|---|
± QNaN,IND | 無 | _DOMAIN |
± INF ( sin , , sinf sinl ) |
INVALID |
_DOMAIN |
如需傳回碼的詳細資訊,請參閱 errno
、 _doserrno
_sys_errlist
和 _sys_nerr
。
備註
因為 C++ 允許多載,所以您可以呼叫採用並傳回 sin
或 float
值的 long double
的多載。 在 C 程式中,除非您使用 <tgmath.h>
宏來呼叫此函式, sin
否則一律會採用 並傳 double
回 。
如果您使用 <tgmath.h> sin()
宏,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學 。
根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
常式 | 必要的標頭 (C) | 必要的標頭 (C++) |
---|---|---|
sin , sinf , sinl |
<math.h> |
<cmath> 或 <math.h> |
sin 宏觀 |
<tgmath.h> |
如需相容性詳細資訊,請參閱相容性。
範例
// crt_sincos.c
// This program displays the sine and cosine of pi / 2.
// Compile by using: cl /W4 crt_sincos.c
#include <math.h>
#include <stdio.h>
int main( void)
{
double pi = 3.1415926535;
double x, y;
x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
}
sin( 1.570796 ) = 1.000000
cos( 1.570796 ) = 0.000000
另請參閱
數學和浮點支援
acos
, acosf
, acosl
asin
, asinf
, asinl
atan
, atanf
, atanl
, atan2
, atan2f
, atan2l
cos
, cosf
, cosl
tan
, tanf
, tanl
_CIsin
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應