The atan()
function returns the inverse tangent of a number. Figure 1 shows the C++ representation of the mathematical expression.
To use the atan()
function, the cmath
header file needs to be included in the program, as shown below:
#include <cmath>
It takes a single number as an argument that can be positive, negative, or zero. This value can be a float
, double
or long double
.
It returns a single value of an angle in radians, ranging from ‘-π/2’ to ‘π/2’. This value can be a float
, double
, or long double
:
double atan(double x);
float atan(float x);
long double atan(long double x);
The following code explains the use of atan()
function in C++. It returns the angle value in radians by default. This value can be converted to degrees, as shown:
#include <iostream> #include <cmath> using namespace std; int main() { double input = 57.6; double resultRadians = atan(input); double resultDegrees = (resultRadians * 180) / M_PI; //M_PI gives the value of Pi in C++ and is defined in the cmath library cout << "atan(50.6) = " << resultRadians << " radians" << endl; cout << "atan(50.6) = " << resultDegrees << " degrees" << endl; return 0; }
RELATED TAGS
CONTRIBUTOR
View all Courses