CKTIS / C
log — C23 mathematical function
`log(x)` from `<math.h>` computes the natural logarithm of positive `x` and returns `ln(x)` as `double`; `logf` and `logl` serve `float` and `long double`. The result is negative for `0 < x < 1`, zero for `x == 1`, and positive for `x > 1`.
Version: C23
Syntax
double log(double x);log(x) from <math.h> computes the natural logarithm of positive x and returns ln(x) as double; logf and logl serve float and long double. The result is negative for 0 < x < 1, zero for x == 1, and positive for x > 1.
The example actually calls log(1.0) and log(exp(1.0)). Output 0.0 1.0 demonstrates the neutral point and inversion of exp at a safe value without confusing the natural logarithm with base ten.
Negative x causes a domain error, while zero may cause a pole error; signaling follows math_errhandling. A correct result extremely close to zero can also cause a range error on underflow. Annex F gives log(±0)=-∞ with FE_DIVBYZERO, log(+∞)=+∞, propagates NaN, and returns positive zero for log(1).
Examples
#include <math.h>
#include <stdio.h>
int main(void){printf("%.1f %.1f\n",log(1.0),log(exp(1.0)));return 0;}
Result
0.0 1.0
The example actually calls `log(1.0)` and `log(exp(1.0))`. Output `0.0 1.0` demonstrates the neutral point and inversion of `exp` at a safe value without confusing the natural logarithm with base ten.