# C++ cmath sin , sinf and sinl function

The C++ cmath sin,sinf and sinl functions compute the sine of the given value.The declaration of the functions are given below:

The first function ‘float sin(float x)’ is called if the argument is float type.

The second ‘double sin(double x)’ is called, if the argument is double type.

The third function is called if the argument is long double type.

The 4th and 5th function are discussed in detail below.

Some points to note (these points are applicable to all the five ‘sin’ functions):

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

ii-The second function ‘double sin(double)‘ is the default function. This function is called if the argument type is not scpecifically mentioned.

Include <typeinfo> to call the ‘typeid()’ function. This function checks the type of the argument.

```float f=1;
long double ld=2;

cout &lt;&lt; &quot;sin(f)=&quot; &lt;&lt; sin(f) &lt;&lt; &quot;\n&quot; //calls the 1st version
&lt;&lt; &quot;sin(ld)=&quot; &lt;&lt; sin(ld) &lt;&lt; endl ; //calls the 3rd version

cout&lt;&lt; sin(89) &lt;&lt; endl ;
//calls the deafault sin function (the 2nd version)

cout&lt;&lt; typeid( sin(89) ).name( ) ;
//checking the return type
```

Output

sin(f)=0.841471
sin(ld)=0.909297
0.860069
d

The ‘d’ at the last output means long double. Which proves that default version is called.

## C++ sinf function

The C++ sinf function is same as the ‘float sin(float)’ function. The character ‘f’ appended to ‘sin’ stands for float, which signify the argument and return type.

```float f=97;

cout&lt;&lt; sin(f) &lt;&lt; endl //calls the 1st version
&lt;&lt; sinf(9) ;

cout&lt;&lt; endl ;

cout&lt;&lt; typeid( sin(f) ).name() &lt;&lt; endl
&lt;&lt; typeid( sinf(97) ).name() ;
```

Output

0.379607
0.379607
f
f

The computed values are the same so are the return type.

###### Property of sinf

If we pass an argument type other than the float type, say double type to ‘sinf’, then this function will always convert the argument type to the float type first and then compute the sine of the float argument value. The return type is also float type.In other words, this function always constrain the parameter type and the return type to the the float type.

```cout&lt;&lt; sin( double(560) )
&lt;&lt; &quot;\n&quot; &lt;&lt; sinf( double(560) ); //calls sinf( float )

cout&lt;&lt; &quot;\nreturn type:&quot; &lt;&lt; typeid( sinf( double(560)) ).name() ;
```

Output,

0.714919
0.714919
return type:f

## C++ sinl function

The C++ sinl is similar to the 3rd version sin function. The ‘l’ in ‘sinl’ means long double, so it accepts the long double type parameter and also returns long double type value.

###### Property of sinl

If we pass an argument type other than the long double type, say float type to ‘cosl’, then this function will always convert the argument type to the long double type first, and then compute the cosine of the long double argument value. The return type is also long double type. In other words, this function always constrain the parameter type and the return type to the the long double type.

```cout&lt;&lt; sin( float(34) )
&lt;&lt; &quot;\n&quot; &lt;&lt; sinl( float(34)) ; //calls sinl(long double)
```

#### Making sin compute any value in degree

The sin functions compute the sine of the value which is of radian type. In the mathematical programs, 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.

The relation between degree and radian is given below,

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.

```double degree=60;
cout&lt;&lt; “sin(60°)=” &lt;&lt; sin( (degree*3.141592)/180 );
```

Output,

sin(60°)=0.866025