Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
valarray
classes:
gslice
gslice_array
indirect_array
mask_array
slice
slice_array
valarray
global functions:
abs
acos
asin
atan
atan2
cos
cosh
exp
log
log10
pow
sin
sinh
sqrt
tan
tanh


tan

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

Compute tangent of valarray elements

Returns a valarray object containing the tangents of all the elements of x.

This function overloads cmath's tan function.

Parameters

x
valarray containing elements of a type for which the unary function tan is defined. Each element's value represents an angle, expressed in radians.

Return value

A valarray object with the tangent values of the elements of x.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// tan valarray example
#include <iostream>
#include <cmath>
#include <valarray>
using namespace std;
int main ()
{
  double val[] = {1.2, 3.14, 5.0};
  valarray<double> foo (val,3);
  valarray<double> bar = tan (foo);
  cout << "foo: ";
  for (size_t i=0; i<foo.size(); ++i)
	  cout << foo[i] << ' ';
  cout << endl;
  cout << "bar: ";
  for (size_t i=0; i<bar.size(); ++i)
	  cout << bar[i] << ' ';
  cout << endl;
  return 0;
}


Output:

foo: 1.2 3.14 5
bar: 2.57215 -0.00159265 -3.38052

See also