log() - Mathematical Function
How is Mathematical Function "log()" used in C++?
How to find the natural logarithm value of a number?
Explanation
log() is a Mathematical Function that returns the natural logarithm for the given "num". This function triggers a domain error when the "num" is negative and a range error occurs if the "num" is zero.
Syntax to find Natural Logarithm :
float log( float num );
double log( double num );
long double log( long double num );
Example :
#include <iostream.h> #include <cmath.h> int main() { cout << "Log of 2 is:: " << log(2) << endl; cout << "Log of 4 is:: " << log(4) << endl; return 0; } |
Result :
Log of 2 is:: 0.693147
Log of 4 is:: 1.38629
In the above example log() is used to find the natural logarithms of 2 and 4.