function template

std::sin

<valarray>
template<class T> valarray<T> sin (const valarray<T>& x);
Compute sine of valarray elements
Returns a valarray object containing the sines of all the elements of x.

This function overloads cmath's sin function.

Parameters

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

Return value

A valarray object with the sine 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
// sin 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 = sin (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: 0.932039 0.00159265 -0.958924

See also