# C programming sin,sinf and sinl

In C programming the <math.h> cos,cosf and cosl compute the cosine of the argument.The declaration of the functions are given below.

1 float sin(float x);
2 double sin(double x);
3 long double sin(long double x);
4 float sinf(float x);
5 long double sinl(long double);

Parameters:
x -The value whose sine is to be computed.

Return type
floating point value -The sine of ‘x’.

All the functions are the same,they compute the sine of ‘x’.The 1st,2nd and the 3rd function have the same name i.e. ‘sin’.The 4th and 5th function have different names.What does having a different names mean is explained in detail below.

Some points to note

i-The argument ‘x‘ is measured in radians.

ii-The second function double sin(double) is the default function called when sin is call in our program.

Code example

double d=123 , x1=0 ;

float f=123 ;

long double ld=123;

printf(“%lf”, sin( d ) ) ; //calls the 2nd version
printf(“\n%f”, sin( f ) ) ; //calls the 1st version
printf(“\n%Lf”, sin( ld ) ) ; //calls the 3rd version

printf(“\n%lf”, sin(x1 ) ) ;
printf(“\n%lf”, sin(INFINITY) ) ;

Output in Visual Studio,

-0.459903
-0.459903
-0.459903
0.000000
-nan(ind)

The macro ‘INFINITY’ stands for the value ‘infinity’ and the the output ‘-nan(ind)’ means the returned value is not representable.

#### sinf

The ‘sinf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘sinf‘ stands for float and it signify the parameter and return type of the function.

Code example

float x= 100 ;

printf(“%f”, sin( x ) ); //Calls the 1st version
printf(“\n%f”, sinf( 100 ) ); Calls the 4th version

Output,

-0.506366
-0.506366

#### sinl

The ‘sinl‘ function is same as the 3rd function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘sinl‘ stands for long double and it signify the parameter and return type of the function.

Code example

long double x= 100 ;

printf(“%Lf”, sin( x ) ); //Calls the 3rd version
printf(“\n%Lf”, sinl( 100 ) ); //Calls the 5th version

Output,

-0.506366
-0.506366

#### Making sin compute any value in degree

The sin,sinf,sinl function compute the sine of the value which is of radian type.In mathematical program you may want to compute the sine of some values which is given in degree.In such case we can convert the degree to radian type by applying a simple conversion rule and compute the sine of the degree.

The relation between degree and radian is given below,

1 degree =(π/180) radian

Multiplying the argument-which is in degree- with (π/180) will yield the corresponding radian value.Computing the sin of this value will yield the sine of the given degree.

Code example

double degree=100 ;

printf(“sinl(100%c)=%lf”, (int)248 , sinl((degree*3.141592) / 180));

Output,

sinl(100°)=0.984808

The char of the integer value 248 is ‘°’-the degree sign.