https://obrhubr.org/logarithm-estimation Niklas Oberhuber Home About Colophon RSS Estimating Logarithms Published on 21st May 2025. 5 minutes long read. --------------------------------------------------------------------- While reading through the fantastic book The Lost Art of Logarithms by Charles Petzold I was nerd-sniped by a simple method of estimating the logarithm of any number base 10. According to the book, it was developed by John Napier (the father of the logarithm) about 1615. In french the natural logarithm is also called "le logarithm neperien" in reference to the mathematician. The Method We note that due to the nature of the logarithm (always referring to base 10 from here one out), the logarithm of any number NNN is approximately equal to the number of digits of NNN minus one. This is quite easy to see when thinking about numbers between 100 and 1000 for example: 100<=N<1000 log[?](100)<=log[?](N) 0) mantissa, exponent = get_scientific(num ** 10) # Apply the trick here by doing the calculation iteratively for _ in range(precision - 1): # Use the properties of exponents # (m x 10^exp)^10 = m^10 x 10^(10 * exp) mantissa = mantissa ** 10 exponent *= 10 mantissa, new_exponent = get_scientific(mantissa) # Calculate the contribution of the new mantissa to the exponent and add it exponent += new_exponent return exponent def logarithm(num, precision): # Count the number of digits n_digits = count_digits(num, precision) # Divide by the exponent result = n_digits / decimal.Decimal(10 ** precision) return f"{result:.{precision}f}" For each additional digit of precision, it calculates Nprev10N^{\text {prev}^{10}}Nprev10, where the scientific form of NprevN^{\text {prev}}Nprev is already known, starting with N10N^{10}N10. This makes the calculation a matter of exponentiating the mantissa by 10 and multiplying the exponent by 10. [DEL:Rinse:DEL] keep the previous results and repeat. I'm not super happy with the implementation because of the decimal import which could probably be made unnecessary by doing some string manipulations. I wrote this little post in order to remember this neat little trick better and to maybe expose some people who wouldn't have read chapter 4 in the book to it. I can only recommend checking out the content straight from the source, online and for free! --------------------------------------------------------------------- If you've noticed any errors or just want to chat, reach out to me @ contact [at] thisdomain.