function template
<valarray>
std::powtemplate<class T> valarray<T> pow (const valarray<T>& x, const valarray<T>& y);template<class T> valarray<T> pow (const valarray<T>& x, const T& y);template<class T> valarray<T> pow (const T& x, const valarray<T>& y);
Compute power of valarray elements
Returns a valarray containing the results of the power operation on all the elements, in the same order. The results calculated are x raised to the power y (xy
).
The function calls pow (unqualified) once for each element in both x and y; If either is a single T value, it is used for all calls.
This function overloads cmath's pow.
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
26
27
28
29
30
31
32
33
// pow valarray example
#include <iostream> // std::cout
#include <cstddef> // std::size_t
#include <cmath> // std::pow
#include <valarray> // std::valarray, std::pow
int main ()
{
std::valarray<double> val (5);
std::valarray<double> results;
for (int i=0; i<5; ++i) val[i]=i+1;
std::cout << "val:";
for (std::size_t i=0; i<val.size(); ++i) std::cout << ' ' << val[i];
std::cout << '\n';
results = std::pow (val,val);
std::cout << "val^val:";
for (std::size_t i=0; i<results.size(); ++i) std::cout << ' ' << results[i];
std::cout << '\n';
results = std::pow (val,2.0);
std::cout << "val^2:";
for (std::size_t i=0; i<results.size(); ++i) std::cout << ' ' << results[i];
std::cout << '\n';
results = std::pow (2.0,val);
std::cout << "2^val:";
for (std::size_t i=0; i<results.size(); ++i) std::cout << ' ' << results[i];
std::cout << '\n';
return 0;
}
val: 1 2 3 4 5 val^val: 1 4 27 256 3125 val^2: 1 4 9 16 25 2^val: 2 4 8 16 32
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4