Logarithms to arbitrary base

The mathematics library in many languages ( e.g. C++) only provides us with natural (base e) logarithms and base 10 logarithms.

When programming, we sometimes need to perform logarithmic calculations that use an arbirary base. It is common, for instance, to need base 2 logarithms in order to work with sizes of binary trees, or base 8 logarithms for octrees.

The logarithm to an arbitrary base b, logb(x), can be computed from the logarithms of x and b with respect to an arbitrary base k using the following formula:


where k could be ‘e’ or ’10′, which allows us to calculate logarithms to an arbitrary base using the standard maths library functions.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>