This is kind of obscure, but I need a function that can be computed very quickly and resembles a^b where a is between 0 and 1 and b is very large. It will be calculated for one a at a time for many b’s. Ideally, the result would be within 0.4%. Thanks in advance.
Share
Pulling my comments into an answer:
Since you mention that
bis large enough to be rounded to an integer, then one approach is to use the Binary Exponentiation algorithm by squaring.Math.pow()is slow because it needs to handle non-integral powers. So might be possible to do better in your case because you can utilize the integer powering algorithms.As always, benchmark your implementation to see if it actually is faster than
Math.pow().Here’s an implementation that the OP found:
Here’s my quick-and-dirty (unoptimized) implementation:
This should work on all positive
pow. But I haven’t benchmarked it againstMath.pow().