This function is defined in <cmath> header file.
[Mathematics] tan-1x = atan(x) [In C++ Programming];
atan() prototype [As of C++ 11 standard]
double atan(double x); float atan(float x); long double atan(long double x); double atan (T x); // For integral type
atan() Parameters
The atan() function takes a single mandatory argument (can be positive, negative, or zero)
atan() Return value
The atan() function returns the value in the range of [-π/2, π/2].
Example 1: How atan() works?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 57.74, result;
result = atan(x);
cout << "atan(x) = " << result << " radians" << endl;
// Output in degrees
cout << "atan(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}
When you run the program, the output will be:
atan(x) = 1.55348 radians atan(x) = 89.0104 degrees
Example 2: atan() function with integral type
#include <iostream>
#include <cmath>
#define PI 3.141592654
using namespace std;
int main()
{
int x = 14;
double result;
result = atan(x);
cout << "atan(x) = " << result << " radians" << endl;
// Output in degrees
cout << "atan(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}
When you run the program, the output will be:
atan(x) = 1.49949 radians atan(x) = 85.9169 degrees
Also Read: