C++ Standard Library C++ STL Library

C++ <valarray> - atan() Function



The C++ <valarray> atan() function returns a valarray containing arc tangent value of all the elements of valarray va, in the same order. This function overloads with cmath's atan() function and calls this function once for each element.

Syntax

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

Parameters

va Specify valarray containing elements of a type for which the function atan() is defined.

Return Value

Returns valarray containing arc tangent value of all the elements of va.

Example:

The example below shows the usage of atan() function.

#include <iostream>
#include <valarray>
using namespace std;

int main (){
  valarray<double> va1 = {0, 0.25, 0.5, 1};
  
  //va2 will contain arc tangent value
  //of all elements of va1
  valarray<double> va2 = atan(va1);
 
  cout<<fixed;
  cout<<"va1 contains: ";
  for(int i = 0; i < va1.size(); i++)
    cout<<va1[i]<<" ";

  cout<<"\nva2 contains: ";
  for(int i = 0; i < va2.size(); i++)
    cout<<va2[i]<<" ";   
  
  return 0;
}

The output of the above code will be:

va1 contains: 0.000000 0.250000 0.500000 1.000000 
va2 contains: 0.000000 0.244979 0.463648 0.785398 

❮ C++ <valarray> Library

5