Search code examples
c++mathlogarithm

A C++ implementation of log that one can specify the base for?


I've been playing around with some math recently and I would like to know if anyone has written/seen a C++ implementation of log that one can specify the base (root..?) for? As in:

Mathematical function definition http://i1091.photobucket.com/albums/i383/dannydeth1/forumla.png

Obviously I would prefer giving the base as an argument: double d = log(b,x);

Thank you for your time and any answers are much appreciated. :}

EDIT: Also, I take it would use Taylor Series?


Solution

  • log_b_(x) = log(x) / log(b). Just do this:

    double log(double base, double x)
    {
        return std::log(x) / std::log(base);
    }