function template
<valarray>

std::tanh

template<class T> valarray<T> tanh (const valarray<T>& x);
Compute hyperbolic tangent of valarray elements
Returns a valarray containing the hyperbolic tangents of all the elements of x, in the same order.

The function calls tanh (unqualified) once for each element.

This function overloads cmath's tanh.

Parameters

x
valarray containing elements of a type for which the unary function tanh is defined.

Return value

A valarray object with the hyperbolic 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
// tanh valarray example
#include <iostream>     // std::cout
#include <cstddef>      // std::size_t
#include <cmath>        // std::tanh(double)
#include <valarray>     // std::valarray, std::tanh(valarray)

int main ()
{
  double val[] = {0.35, 1.22, 3.4};
  std::valarray<double> foo (val,3);

  std::valarray<double> bar = tanh (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;
}


Output:

foo: 0.35 1.22 3.4
bar: 0.335376 0.839654 0.997775

See also