Search code examples
cmathlogarithm

How I can use logarithms in C language


I want to execute logx in C, but I found out that the math library in C, only provides logs with bases e and 10. How is it possible to get a logarithm in some other basis?


Solution

  • http://en.wikipedia.org/wiki/Logarithm#Change%5Fof%5Fbase

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

    log_b(x) = ln(x) / ln(b)