Problems with Log function in Boost C++ libraries -


i have code in order logarithm of number given 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) // ==> log(base, arg) = log(e, arg) / log(e, base) res = (double)(res / ((double)boost::math::log1p(base - 1))); return res; 

as can see boot libs define neperian log , there tricky way log because lib gives not log(x) log(x+1). can see problem solved giving argument arg - 1 , should work.

well works, neperian log ok, mean, if run 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) // ==> log(base, arg) = log(e, arg) / log(e, base) //res = (double)(res / ((double)boost::math::log1p(base - 1))); return res; 

everything ok, right when perform base change not good, wrong results... don't know, maybe it's math issue... know log(basea, x) = log(baseb, x)/log(baseb, basea)...

where do wrong??

well, may math issue concerning numerical stability , on... log in different base, what's best practice???????

i not sure happening may having rounding issue. issue 1 + delta delta small doubles not built hold delta precision 1 dominates enormously , delta considered insignificant.

the purpose of boost library allow pass in 1 , delta separately not lose precision of delta when take log, give number close 0.

an example delta = 0.00000000123456789

if add 1 subtract 1 again not see numbers double holds 15 places of precision number above +1 gives requires 17 whereas numbe have printed uses 9 places because leading zeros don't count.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -