log()

Christine_Yang271 total contributions
Published Sep 14, 2022Updated Dec 21, 2022
Contribute to Docs
The log()
function returns the natural, base-e
logarithm of the argument. This is the inverse of the exp()
function.
Syntax
log(x)
If the x
parameter is less than or equal to zero, then a domain error will occur. If x
is equal to zero, a pole error may occur where the result has reached the point of infinity and cannot be expressedly returned.
Example
The following example uses the log()
function to find the natural log of 5
:
#include <iostream>#include <math.h>int main() {double x = 5;double result;result = log(x);std::cout << "The log of " << x << " is " << result << "\n";// Output: The log of 5 is 1.60944}
Codebyte Example
The following example is runnable and returns the natural log of 10
:
All contributors
- Christine_Yang271 total contributions
- garanews222 total contributions
- HitarthKothari4 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.