I have this code in order to get a logarithm of a number given a generic base:
#include <boost/math/special_functions/powm1.hpp>
#include <boost/math/special_functions/log1p.hpp>
#include <boost/math/special_functions/sqrt1pm1.hpp>
// ...
// Boost Log returns boost::math::log1p(x) = log(e, x + 1)
double res = (double)(boost::math::log1p(arg - 1));
// Base conversion: log(new, y) = log(old, y) / log(old, new)
// Then ==> log(base, arg) = log(e, arg) / log(e, base)
res = (double)(res / ((double)boost::math::log1p(base - 1)));
return res;
As you can see boot libs define only neperian log and there is also a tricky way to get that log because what that lib gives back to you is not log(x) but log(x+1). As you can see this problem is solved by giving as the argument arg - 1 and everything should work.
WELL It works, but only the neperian log is ok, I mean, If I run this code:
#include <boost/math/special_functions/powm1.hpp>
#include <boost/math/special_functions/log1p.hpp>
#include <boost/math/special_functions/sqrt1pm1.hpp>
// ...
// Boost Log returns boost::math::log1p(x) = log(e, x + 1)
double res = (double)(boost::math::log1p(arg - 1));
// Base conversion: log(new, y) = log(old, y) / log(old, new)
// Then ==> log(base, arg) = log(e, arg) / log(e, base)
//res = (double)(res / ((double)boost::math::log1p(base - 1)));
return res;
Everything is ok, but right when I perform a base change everything is not good, I get back wrong results... I don't know, maybe it's a math issue... I know that log(basea, x) = log(baseb, x)/log(baseb, basea)...
Where do I do wrong??
Well, may be it is a math issue concerning numerical stability and so on... to get a log in a different base, what's the best practice???????