<valarray>
template<class T> valarray<T> log (const valarray<T>& x);
Compute natural logarithm of valarray elements
Returns a valarray object containing the natural logarithm (base-e logarithm) of all the elements of x.
This function overloads cmath's log function.
Parameters
- x
- valarray containing elements of a type for which the unary function log is defined.
Return value
A valarray object with the natural logarithms 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
|
// log valarray example
#include <iostream>
#include <cmath>
#include <valarray>
using namespace std;
int main ()
{
double val[] = {5.0, 6.6, 8.0, 9.9};
valarray<double> foo (val,4);
valarray<double> bar = log (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: 5 6.6 8 9.9
bar: 1.60944 1.88707 2.07944 2.29253
|
See also
log10 | Compute common logarithm of valarray elements (function template) |
exp | Compute exponential of valarray elements (function template) |
pow | Compute power of valarray elements (function template) |
|