C programming math.h atan,atanf and atanl


In C programming the <math.h> atan ,atanf and atanl functions compute the arc tangent of the argument.The declaration of the function is given below.

1 float asin(float x);
2 double asin(double x);
3 long double asin(long double x);
4 float asinf(float x);
5 long double asinl(long double x);

Parameters:
x -A floating point value.

Return type
floating point value -The arc tangent of the argument passed.

All the functions are the same,they compute the arc tangent of the argument.The 1st,2nd and the 3rd function have the same name i.e. ‘atan’.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-i-There is no restriction on the range of value 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 sine means inverse of sine,so atan(x) is same as tan-1(x).

Code example

double d1 = 0.12 , d2 = 120 ;

float f1 = 0.12 ;

long double ld = 0.12 ;

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

printf(“\n%lf”, atan(d2) ) ;
printf(“\n%lf”, atan(INFINITY) ) ;

Output in Visual Studio,

0.119429
0.119429
0.119429
1.562463
1.570796






atanf

The ‘atanf‘ 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 ‘atanf‘ stands for float and it signify the parameter and return type of the function.

Code example

float f = 0.77 ;

printf(“%f”, atan( f ) ) ; //Calls the 1st version
printf(“\n%f”, atanf( 0.77 ) ) ; //same as above

Output in Visual Studio,

0.610726
0.610726


atanl

The ‘atanl‘ 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 ‘atanl‘ stands for long double and it signify the parameter and return type of the function.

Code example

long double ld = 0.671 ;

printf(“%Lf”, atan( ld ) ) ; //Call the 3rd version
printf(“\n%Lf”, atanl( 0.671 ) ) ; //same as above

Output ,

0.590997
0.590997



Getting degree instead of radian with atan

The C atan, atanf and atanl return the value in radian,to get the value as degree apply the simply operation given below.

Now,

1 radian = (180/3.141592) degree

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

Code example

printf( “atanl(0.345)=%lf%c”, ( (atanl( 0.345 )*180)/3.141592 ) , (int)248 );

Output,

atanl(0.345)=19.034438°