algorithm - Integer logarithm of fractional bases -


i'm working on program problem has natural logarithmic scale.

so far i'm using base 2, nice implementation of unsigned int log2(uint64_t) (in c/c++), found here.

however, found base 2 problem: need use fractional bases, e.g. 3/2.

is aware of implementation kind of operation?

my current solution round(log(x)/log(base)) round returns integer, hopping, @ least, avoid 2 evaluations of log.

log(base) constant, evaluate once , take reciprocal (to turn onto multiply rather expensive divide).

const float k = 1.0f / log(base); // init constant once  y = round(log(x) * k); // each evaluation requires 1 log,                        // 1 multiply , 1 round 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -