sin
, sinf
, sinl
Calculates the sine of a floating-point value.
Syntax
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
Parameters
x
Angle in radians.
Return value
The sin
functions return the sine of x
. If x
is greater than or equal to 263, or less than or equal to -263, a loss of significance in the result occurs.
Input | SEH exception | _matherr exception |
---|---|---|
± QNaN, IND | None | _DOMAIN |
± INF (sin , sinf , sinl ) |
INVALID |
_DOMAIN |
For more information about return codes, see errno
, _doserrno
, _sys_errlist
, and _sys_nerr
.
Remarks
Because C++ allows overloading, you can call overloads of sin
that take and return float
or long double
values. In a C program, unless you're using the <tgmath.h>
macro to call this function, sin
always takes and returns double
.
If you use the <tgmath.h> sin()
macro, the type of the argument determines which version of the function is selected. See Type-generic math for details.
By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.
Requirements
Routine | Required header (C) | Required header (C++) |
---|---|---|
sin , sinf , sinl |
<math.h> |
<cmath> or <math.h> |
sin macro |
<tgmath.h> |
For more compatibility information, see Compatibility.
Example
// 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
See also
Math and floating-point support
acos
, acosf
, acosl
asin
, asinf
, asinl
atan
, atanf
, atanl
, atan2
, atan2f
, atan2l
cos
, cosf
, cosl
tan
, tanf
, tanl
_CIsin
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho