sin, sinf, sinl

Calculates the sine of a floating-point value.


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


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
± INF (sin, sinf, sinl) INVALID _DOMAIN

For more information about return codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.


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.


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.


// 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