function template
<valarray>
std::exp
template<class T> valarray<T> exp (const valarray<T>& x);
Compute exponential of valarray elements
Returns a valarray object containing the exponential function values of all the elements of x, in the same order.
The function calls exp (unqualified) once for each element.
This function overloads cmath's exp.
Parameters
- x
- valarray containing elements of a type for which the unary function exp is defined.
Return value
A valarray object with the exponential function 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
|
// exp valarray example
#include <iostream> // std::cout
#include <cstddef> // std::size_t
#include <cmath> // std::exp(double)
#include <valarray> // std::valarray, std::exp(valarray)
int main ()
{
double val[] = {1.1, 2.2, 4.4, 8.8};
std::valarray<double> foo (val,4);
std::valarray<double> bar = exp (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: 1.1 2.2 4.4 8.8
bar: 3.00417 9.02501 81.4509 6634.24
|
See also
- exp (cmath)
- Compute exponential function (function)
- log
- Compute natural logarithm of valarray elements (function template)
- pow
- Compute power of valarray elements (function template)