std::log(std::valarray)

Header: <valarray>

For each element in va computes natural logarithm of the value of the element.

# Declarations

template< class T >
valarray<T> log( const valarray<T>& va );

# Parameters

# Return value

Value array containing natural logarithms of the values in va.

# Notes

Unqualified function (log) is used to perform the computation. If such function is not available, std::log is used due to argument-dependent lookup.

The function can be implemented with the return type different from std::valarray. In this case, the replacement type has the following properties:

# Example

#include <iomanip>
#include <iostream>
#include <valarray>
 
void show(char const* title, const std::valarray<double>& va)
{
    std::cout << title << " :" << std::right << std::fixed;
    for (double x : va)
        std::cout << std::setw(10) << x;
    std::cout << '\n';
}
 
int main()
{
    const std::valarray<double> n{0.0, 1.0, 2.0, 3.0};
    const std::valarray<double> exp_n{std::exp(n)};
    const std::valarray<double> log_exp_n{std::log(exp_n)};
 
    show("n      ", n);
    show("eⁿ     ", exp_n);
    show("log(eⁿ)", log_exp_n);
}

# See also