- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Valarray::atan Function
The atan() function in the valarray class is used to create a valarray with elements calculated as tan-1 for each element in the original valarray.
The atan() function of cmath is overload with in this function, which calls it once for each element. Atan() returns values in the range [-x/2,x/2] and is compatible with all real numbers.
Syntax
Following is the syntax for C++ Valarray::atan Function −
atan (const valarray<T>& x);
Parameters
x − It is containing elements of a type for which the unary function atan is defined.
Examples
Example 1
Let's look into the following example, where we are going to take number as a input, passing it to the atan() function and retrieving the output.
#include <iostream> #include <cmath> using namespace std; int main() { double x =12.43,result; result =atan (x); cout << "atan(""<<x<<"") = " << result << endl; return 0; }
Output
Let us compile and run the above program, this will produce the following result −
atan(<x<) = 1.49052
Example 2
Following is the example, where we are going to use atan() function and retrieving the output of both original valarray and atan valarray.
#include <iostream> #include <valarray> using namespace std; int main() { valarray<double> myvalarray = { 1.2, -0.6, 4, -5.67, -2 }; cout << "The Orignal Valarray : "; for (double& ele : myvalarray) cout << ele << " "; valarray<double> atanvalarray = atan(myvalarray); cout << "\nThe atan Valarray : "; for (double& ele : atanvalarray) cout << ele << " "; return 0; }
Output
Let us compile and run the above program, this will produce the following result −
The Orignal Valarray : 1.2 -0.6 4 -5.67 -2 The atan Valarray : 0.876058 -0.54042 1.32582 -1.39622 -1.10715
Example 3
Considering the another scenario, where we are going to use atan() function and retrieving the output in degrees.
#include <iostream> #include <cmath> #define PI 3.141592654 using namespace std; int main() { int a = 25; double result; result = atan(a); cout << "atan(a) = " << result*180/3.1415 << " degrees" << endl; return 0; }
Output
Let us compile and run the above program, this will produce the following result −
atan(a) = 87.712 degrees
Example 4
In the following example, we are going to use the atan() function and retrieving the output in radians.
#include <iostream> #include <cmath> using namespace std; int main() { double x = 142.5; double resultRadians = atan(x); cout << "atan(x) = " << resultRadians << " radians" << endl; return 0; }
Output
Let us compile and run the above program, this will produce the following result −
atan(x) = 1.56378 radians
To Continue Learning Please Login
Login with Google