A C++ implementation of log that one can specify the base for? [duplicate]
Question
This question already has an answer here:
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);
}
OTHER TIPS
It's straightforward to implement yourself:
double
logb( double n, double b )
{
return log(n) / log(b);
}
Is it generally useful? Or are practically all of the uses subsumed by log
, log10
and log2
?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow