# Thread: (un)natural logarithm function using the wrong base

1. ## (un)natural logarithm function using the wrong base

The following code produces logarithms apparently using base 2.71826 instead of base 10. What could I be doing wrong in a function so simple?
Code:
```#include <stdio.h>
#include <math.h>

int main()
{ double d = 100.0;
double num;
scanf("%g", &num);
printf("log (%g) = %g\n", num, log(num));
printf("log (%g) = %g\n", d, log(d));
return (0);
}```
Input to scanf:
4
Output
Code:
```Ready
4
log (1.21742e-306) = -704.394
log (100) = 4.60517``` 2. Which compiler are you using?

What results do you get? 3. I think you're looking for log10. 4. log - C++ Reference

^ is the natural logarithm 5. Just FYI, you can calculate the logarithm of a number to any base using log(number)/log(base). 6. Wow. Thanks for telling me about log10. I got confused and thought log base 10 was natural. Now I remember what e is. 7. Common logarithm is to base 10. Natural logarithm is to base e (approximately 2.71828...).

Mathematically the natural log of x is often described using the notation ln(x) - goes to show that the people who specified the C standard library were not actually mathematicians.

For those familiar with calculus: the term "natural" comes the fact that the derivative of ln(x) with respect to x is 1/x. Popular pages Recent additions log, math.h 