log() Function in C++ (original) (raw)
Last Updated : 17 Sep, 2025
The std::log() in C++ is a built-in function that is used to calculate the natural logarithm ****(base** e) of a given number. The number can be of any data type i.e. int, double, float, long long. It is defined inside the ****** header file.
C++ `
// C++ program to show the working of log() #include <bits/stdc++.h> using namespace std;
int main() {
// Return positive integer if the number is
// greater than 1
cout << log(11) << endl;
// Return negative integer if the number is
// between 0 and 1 (not inclusive)
cout << log(0.5) << endl;
// Return 0 if the number is 1
cout << log(1) << endl;
// Return -inf (infinity) if the number is 0
cout << log(0) << endl;
// Return inf (infinity) if the number is very large
cout << log(1e1000) << endl;
// Return NaN (Not a Number) if the number is ngative
cout << log(-11) << endl;
return 0;}
`
Output
2.3979 -0.693147 0 -inf inf nan
Syntax
**std::log(n);
**Parameters
- **n: Value whose natural logarithm is to be found.
**Return Value
- Returns the natural log (base e) of the value