
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Valarray Library - log Function
Description
It returns a valarray containing the natural logarithm (base-e logarithm) of all the elements of x, in the same order.
Declaration
Following is the declaration for std::log function.
template<class T> valarray<T> log (const valarray<T>& x);
C++11
template<class T> valarray<T> log (const valarray<T>& x);
Parameters
x − It is containing elements of a type for which the unary function abs is defined.
Return Value
It returns a valarray containing the natural logarithm (base-e logarithm) of all the elements of x, in the same order.
Exceptions
Basic guarantee − if any operation performed on the elements throws an exception.
Data races
All elements effectively copied are accessed.
Example
In below example explains about std::log function.
#include <iostream> #include <cstddef> #include <cmath> #include <valarray> int main () { double val[] = {5.0, 6.0, 8.0, 9.5}; std::valarray<double> foo (val,4); std::valarray<double> bar = log (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; }
Let us compile and run the above program, this will produce the following result −
foo: 5 6 8 9.5 bar: 1.60944 1.79176 2.07944 2.25129
valarray.htm
Advertisements