##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::log

From cppreference.com
< cpp‎ | numeric‎ | math

Defined in header `<cmath>` |  |
float log( float arg ); |  |
double log( double arg ); |  |
long double log( long double arg ); |  |
double log( Integral arg ); |  | (since C++11)

Computes the natural (base e) logarithm of `arg`.

### [edit] Parameters

arg | - | value of floating-point or Integral type

### [edit] Return value

Natural logarithm of `arg`.

Domain error occurs if `arg` is negative. NAN is returned in that case.

Range error occurs if `arg` is ​0​. -HUGE_VAL is returned in that case.

### [edit] Example

The following code computes the binary (base 2) logarithm with help of natural logarithm.

Run this code

    #include <cmath>
    #include <iostream>

    int main()
    {
        double base = 2.0;
        double arg  = 256.0;
        double result = std::log(arg) / std::log(base);

        std::cout << result << '\n';
    }

Output:

    8

### [edit] See also

exp | returns e raised to the given power (ex) (function) [edit]
log10 | computes common (base 10) logarithm (log10(x)) (function) [edit]
pow | raises a number to the given power (xy) (function) [edit]
log(std::complex) | complex natural logarithm with the branch cuts along the negative real axis (function template) [edit]
log(std::valarray) | applies the function std::log to each element of valarray (function template) [edit]
C documentation for log

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/numeric/math/log&oldid=67126"