I’m trying to calculate logab (and get a floating point back, not an integer). I was planning to do this as log(b)/log(a). Mathematically speaking, I can use any of the cmath log functions (base 2, e, or 10) to do this calculation; however, I will be running this calculation a lot during my program, so I was wondering if one of them is significantly faster than the others (or better yet, if there is a faster, but still simple, way to do this). If it matters, both a and b are integers.
I’m trying to calculate log a b (and get a floating point back, not
Share
Since
bandaare integers, you can use all the glory of bit twiddling to find their logs to the base 2. Here are some:I’ll leave it to you to choose the best “fast-log” function for your needs.