sin(), sinf(), sinl() — Calculate sine

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double sin(double x);
float sin(float x);                  /* C++ only */
long double sin(long double x);      /* C++ only */
float sinf(float x);
long double sinl(long double x);

General description

Calculates the sine of x, with x expressed in radians.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

If successful, the function returns the calculated value, expressed as a double, float, or long double. Otherwise, if the result is an underflow, the function returns 0 and sets the errno to ERANGE.

Special Behavior for XPG4.2: The following error is added:
Error Code
Description
EDOM
The argument exceeded an internal limit for the function (approximately 250).

Example

CELEBS27
⁄* CELEBS27                                      

   This example computes y as the sine of &pi.&slr.2.                           
                                                                                
 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   double pi, x, y;                                                             
                                                                                
   pi = 3.1415926535;                                                           
   x = pi⁄2;                                                                    
   y = sin(x);                                                                  
                                                                                
   printf("sin( %lf ) = %lf\n", x, y);                                          
}                                                                               
Output
sin( 1.570796 ) = 1.000000

Related information