My question is related to Calculating logs and fractional exponents by hand, but despite that question's title, all answers there focus on logarithms. I am interested in fractional exponents alone.
The programming language I am working with doesn't support floating-point numbers (i.e. fractional numbers). To work around this, I am emulating fractions via fixed-point representation with 18 decimals (the language can go as high as $2^{256} – 1$). For example, I would write $\pi$ as $3141592653589793238$.
I need to calculate the exponential function when the exponent is a fractional number, but I can only use:
- Basic arithmetic operations like addition, subtraction, multiplication and division (note: division rounds down, no fractional part allowed)
- The exponentiation function (**) but only if the exponent is a whole number
The language doesn't support roots or other advanced functions natively.
Is there any mathematical trick that I can use to accurately estimate fractional exponents?
Best Answer
You can handle the exponents as
$$x^{p/q}=\sqrt[q]{x^p}.$$
The powers $x^p$ aren't so problematic, though for large values you may have to truncate and use a form of floating-point. So your question amounts to taking $q^{\text{th}}$ roots. Several approaches are possible:
solve $y^q=x^p$ by dichotomic search. You'll need to compute the $q^{\text{th}}$ powers of several $y$ candidates. For the starting bracketing of $y$, you can try successive doublings ($y=1,y=2,y=4,\cdots$) until $y^q$ exceeds $x^p$.
solve $y^q=x^p$ by Newton's iterations,
$$y_{n+1}=\frac{(q-1)y_n^q+x^p}{qy_n^{q-1}}.$$
$$(10m+d)^q=\sum_{k=0}^q\binom qk10^km^kd^{q-k}.$$
Alternatively, write the fraction in binary, $$\frac pq\simeq\sum_{i=0}^lb_i2^{-i}.$$ Then use a square root algorithm to compute the powers $x^{2^{-i}}$ iteratively. Finally, take the product of the powers where the bit is $1$.