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++ 允许重载,因此你可以调用采用并返回 sinfloat 值的 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

另请参阅

数学和浮点支持
acosacosfacosl
asinasinfasinl
atanatanfatanlatan2atan2fatan2l
coscosfcosl
tantanftanl
_CIsin