C++ Math atan
The function computes the inverse tangent of a number given in radian.
Syntax
Suppose a number is 'x'. Syntax would be:
float atan(float x);
double atan(double x);
long double atan(long double x);
double atan(integral x);
Note: If the value passed is an integer type, then it is cast to double.
Parameter
x : The value whose inverse tangent is to be calculated.
Return value
It returns the value in the range[-∏/2, ∏/2].
Example 1
Let's see a simple example when the value of x is zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float degree=0;
float x=degree*3.14/180;
std::cout << "Value of tangent is :" <<tan(x)<< std::endl;
cout<<"Inverse of tangent is :"<<atan(x);
return 0;
}
Output:
Value of tangent is :0
Inverse of tangent is :0
In this example, atan function calculates the inverse tangent of a number when the value of x is equal to zero.
Example 2
Let's see the simple example when the value of x is negative.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float degree= -67;
float x=degree*3.14/180;
std::cout << "Value of tangent is : " <<tan(x)<< std::endl;
cout<<"Inverse of tangent is : "<<atan(x);
return 0;
}
Output:
Value of tangent is : -2.35197
Inverse of tangent is : -0.863063
In this example, atan function calculates the inverse tangent of a number when the value of x is negative.
Example 3
Let's see a simple example when the value of x is positive.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float degree=30;
float x=degree*3.14/180;
std::cout << "Value of tangent is : " <<tan(x)<< std::endl;
cout<<"Inverse of tangent is : "<<atan(x);
return 0;
}
Output:
Value of tangent is : 0.576996
Inverse of tangent is : 0.48214
In this example, atan function calculates the inverse tangent of a number when the value of x is positive.