Calculating non-integer exponents

751 Views Asked by At

I'm trying to create a fully functioning calculator in Ruby and have been stuck for quite some time on calculating non-integer exponents, e.g. $3^{2.4}$. I would like to be able to support decimal powers without using any libraries. Knowing how to work out a given log by hand would also be useful as I would like to add log support in eventually. I have plans to look into Taylor expansion as suggested by this post but haven't really had time. I'm open to any and all suggestions.


UPDATE: I figured it out. To calculate $3^{2.4}$, for example, you would first convert it to a decimal leaving $3^{(\frac{24}{10})}$. Optionally, you would then reduce it leaving $3^{(\frac{12}{5})}$. From here, you take the base to the power of the numerator, $3^{12}$, and take it to the root of the denominator finally giving you $\sqrt[5]{3^{12}}$ which can be calculated with the Nth Root Algorithm, and a list of this algorithm being implemented in various programming languages can be found here.

1

There are 1 best solutions below

0
On

Iterative methods for computing logarithms are notoriously slow. Check out the following recent paper: Fast log algorithm