title: Problems with Log function in Boost C++ libraries
body: <p>I have this code in order to get a logarithm of a number given a generic base:</p>
  
  <pre><code>#include &lt;boost/math/special_functions/powm1.hpp&gt;
  #include &lt;boost/math/special_functions/log1p.hpp&gt;
  #include &lt;boost/math/special_functions/sqrt1pm1.hpp&gt;
  // ...
  // 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 ==&gt; log(base, arg) = log(e, arg) / log(e, base)
  res = (double)(res / ((double)boost::math::log1p(base - 1)));
  return res;
  </code></pre>
  
  <p>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.</p>
  
  <p>WELL It works, but only the neperian log is ok, I mean, If I run this code:</p>
  
  <pre><code>#include &lt;boost/math/special_functions/powm1.hpp&gt;
  #include &lt;boost/math/special_functions/log1p.hpp&gt;
  #include &lt;boost/math/special_functions/sqrt1pm1.hpp&gt;
  // ...
  // 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 ==&gt; log(base, arg) = log(e, arg) / log(e, base)
  //res = (double)(res / ((double)boost::math::log1p(base - 1)));
  return res;
  </code></pre>
  
  <p>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)...</p>
  
  <p>Where do I do wrong??</p>
  
  <p>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???????</p>