C++ Valarray Library - atan Function


Advertisements

Description

It returns a valarray object containing the principal values of the arc tangent of all the elements of x, expressed in radians, in the same order.

Declaration

Following is the declaration for std::atan function.

template<class T> valarray<T> atan (const valarray<T>& x);

C++11

template<class T> valarray<T> atan (const valarray<T>& x);

Parameters

x − It is containing elements of a type for which the unary function abs is defined.

Return Value

It returns a valarray object containing the principal values of the arc tangent of all the elements of x, expressed in radians, in the same order.

Exceptions

Basic guarantee − if any operation performed on the elements throws an exception.

Data races

All elements effectively copied are accessed.

Example

In below example explains about std::atan function.

#include <iostream>     
#include <cstddef>      
#include <cmath>        
#include <valarray>     

int main () {
   double val[] = {0.0, 0.25, 0.5, 0.75, 1.0};
   std::valarray<double> foo (val,5);

   std::valarray<double> bar = atan (foo);

   std::cout << "foo:";
   for (std::size_t i=0; i<foo.size(); ++i)
      std::cout << ' ' << foo[i];
   std::cout << '\n';

   std::cout << "bar:";
   for (std::size_t i=0; i<bar.size(); ++i)
      std::cout << ' ' << bar[i];
   std::cout << '\n';

   return 0;
}

Let us compile and run the above program, this will produce the following result −

foo: 0 0.25 0.5 0.75 1
bar: 0 0.244979 0.463648 0.643501 0.785398
valarray.htm
Advertisements