## 2.5 Computing Common Logarithms

For common logs, we can write any number in scientific notation and compute its logarithm by breaking it into two parts. Suppose $$x$$ is written in scientific notation as $$x = a \times 10^n$$ where $$1\le a < 10$$ and $$n$$ is an integer. Then $x = a/10 \times 10^{n+1}$ and $\ln x = \ln(a/10) + (n+1)\; \ln 10$ from which $\log x = \frac{\ln x}{\ln 10} = \frac{\ln (a/10)}{\ln 10} + n+1 .$ Since $$a$$ was defined to be between 1 and 10, then $$a/10$$ is between 0.1 and 1 and we can use our power series expansion for $$\ln(x)$$ in our calculations. We are now in a position to create a function to compute common logarithms for general numbers. Here is an example computer code to do just that, re-using our previous function for computing natural logarithms:

logCom = function(x){
Num = strsplit(format(x, scientific=T),"e")[]
a   = as.numeric(Num)
p   = as.integer(Num)
lnX(a/10)/ln10 + p + 1
}

Below are a few examples, using our function above, of the calculation of various common logarithms:

 log 0.718 = -0.14388 log 1.25 = 0.09691 log 2 = 0.30103 log e = 0.43429 log 200 = 2.30103 log 425 = 2.62839 log 3.4$$\times 10^5$$ = 5.53148