I'm programming a library for arbitrary precision arithmetic. The last problem I'm facing is the power function. I figured out to compute 2 ^ (y log2(x))
instead of x ^ y
and there remains a single subproblem: How can I efficiently compute 2 ^ x
with x
in the range (0,1)
(zero and one excluded).
Since I obviously store rationals anyway, x
has the form p/q
(p < q
). Therefore I could calculate the q
-th root of 2
(Wikipedia's n-th root algorithm https://en.wikipedia.org/wiki/Nth_root_algorithm) and then exponentiate the result by p
.
However, this seems very inefficient. Is there any superior algorithm? Thanks for your help.