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^p\) where \(1\le a < 10\) and \(p\) is an integer. Then \[ x = a/10 \times 10^{p+1} \] and \[ \ln x = \ln(a/10) + (p+1)\; \ln 10 \] from which \[ \log x = \frac{\ln (a/10)}{\ln 10} + p+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 to do just that, re-using our previous function for computing natural logarithms:

logCom = function(x){
   Num = strsplit(format(x, scientific=T),"e")[[1]]
   a   = as.numeric(Num[1])
   p   = as.integer(Num[2])
   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