Export (0) Print
Expand All

log (<valarray>)

Operates on the elements of an input valarray, returning a valarray whose elements are equal to the natural logarithm of the elements of the input valarray.

template<class Type> 
   valarray<Type> log( 
      const valarray<Type>& _Left 
   );

_Left

The input valarray whose elements are to be operated on by the member function.

A valarray whose elements are equal to the absolute value of the elements of the input valarray.

// valarray_log.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
#include <iomanip>

int main( )
{
   using namespace std;
   int i;

   valarray<double> va1 ( 9 );
   for (i = 0 ; i < 9 ; i++ ) 
      va1 [ i ] =  10 * i;
   valarray<double> va2 ( 9 );

   cout << "Initial valarray:";
   for ( i = 0 ; i < 9 ; i++ )
      cout << " " << va1 [ i ];
   cout << endl;

   va2 = log ( va1 );
   cout << "The natural logarithm of the initial valarray is:\n";
   for ( i = 0 ; i < 9 ; i++ )
      cout << va2 [ i ] << endl;
}
Initial valarray: 0 10 20 30 40 50 60 70 80
The natural logarithm of the initial valarray is:
-1.#INF
2.30259
2.99573
3.4012
3.68888
3.91202
4.09434
4.2485
4.38203

Header: <valarray>

Namespace: std

Show:
© 2014 Microsoft