(un)natural logarithm function using the wrong base

• 08-12-2010
Gerling
(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;     printf("Ready\n");     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```
• 08-12-2010
Salem
Which compiler are you using?

What results do you get?
• 08-12-2010
pianorain
I think you're looking for log10.
• 08-12-2010
KBriggs
log - C++ Reference

^ is the natural logarithm
• 08-12-2010
Sebastiani
Just FYI, you can calculate the logarithm of a number to any base using log(number)/log(base).
• 08-12-2010
Gerling
Wow. Thanks for telling me about log10. I got confused and thought log base 10 was natural. Now I remember what e is.
• 08-13-2010
grumpy
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.