C++ cmath atan,atanf and atanl function


The C++ cmath atan,atanf and atanl function computes the arc tangent of the given value.The declaration of the functions are given below:

1 float atan(float x);
2 double atan(double x);
3 long double atan(long double x);
4 float atanf(float x);
5 long double atanl(long double x);

Some points to note:

i-i-There is no restriction on the range of values that can be used as argument.

ii-The returned value is in the interval [-π/2,+π/2] radians.

iii-The second version is the default version that is called when atan is called in our program.

iv-When the argument passed is int type the default version is called.

Note arc tangent means inverse of tangent,so atan(x) is same as tan-1(x).

Code example

#include <typeinfo>

cout<< atan(0.23) << endl
<< atan(9090);

cout<< typeid( asine(0.23) ).name( ) ;

Output

0.226068
1.57069
d (means ‘double’)



atanf and atanl

atanf function

The first version atan function is similar to atanf function.Both these functions use float as the argument and the return type.The ‘f’ in atanf means float which also signify the type of the argument and the return value.

Code example

float f=0.2;

cout<< atan(f) << endl
<< atanf(0.2) << endl ;

cout<< typeid( atan(f) ).name( ) << endl
<< typeid( atanf(0) ).name( ) << endl ;

Output

0.197396
0
f
f

atanl function

The atanl function is similar to the 3rd version atan function.Both the functions have long double as the argument and return type.The argument and return type in atanl function is signified by the character ‘l’ which stands for long double.

Code example

long double ld=0.22 ;

cout<< atan(ld) << endl
<< atanl(0.22) << endl ;

cout<< typeid( atan(ld) ).name( ) << endl
<< typeid( atanl(0.22) ).name( ) << endl ;

Output

0.21655
0.21655
e (means ‘long double’)
e (means ‘long double’)





getting degree instead of radian with atan

The value returned by atan is in radian.You can convert it to degree by using the simple conversion rule.

The relation between radian and degree is shown below,

1 radian = (180/3.141592) degree

Multiplying the output obtained with (180/3.141592) gives the degree of the atan computed value.

Code example

cout<< “atan(0.5°)=” << ( atan(1)*180 )/3.141592 << “°” << endl ;

Output

atan(1)=45°