一般的な基数が与えられた数値の対数を取得するために、次のコードがあります。
#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;
ご覧のとおり、ブート ライブラリは neperian ログのみを定義しており、そのログを取得するためのトリッキーな方法もあります。なぜなら、そのライブラリが返すのは log(x) ではなく log(x+1) だからです。ご覧のとおり、この問題は引数 arg - 1 を指定することで解決され、すべてが機能するはずです。
うまく機能しますが、ネペリアンログだけは問題ありません。つまり、次のコードを実行すると:
#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;
すべては問題ありませんが、ベースの変更を実行すると、すべてがうまくいかず、間違った結果が返されます...わかりません。おそらく数学の問題です... log(basea, x) = log (baseb, x)/log(baseb, basea)...
どこで間違っていますか??
まあ、それは数値安定性などに関する数学の問題かもしれません...別のベースでログを取得するには、ベストプラクティスは何ですか???????