I have problem calculating raise a
to the power of b
(a^b) where b is a floating point number.
In my case, b=-1.45. So the expression is a^(-1.45).
I'm using PIC18F4520 microcontroller and I don't know how to implement it in assembly language or its routine as well.
Electronic – How to code in assembly language for floating point exponentiation
assemblyfloating pointpic
Best Answer
Note that just because
b
isn't an integer, it doesn't mean that it is necessarily floating-point. For example, it could be expressed as the integer ratio \$-1.45 = \frac{-29}{20}\$.You need to specify what the type and range of
a
is, and what kind of accuracy you require in your application. You also haven't specified what you want the output to look like. As @jonathanjo pointed out, all answers except for a=1 are fractions less than 0.5. Also, since exponentiation is a nonlinear operation, it's important to understand what real-world values the integer values of 'a' represent.For what it's worth, arbitrary exponentiation is usually implemented as a 3-step process: log, multiply, exponentiate:
$$a^b \equiv \exp(b \cdot \log(a))$$
You can use any convenient base for the log() and exp() operations, as long as they're the same. 2, \$e\$ and 10 are popular choices.
CORDIC is one way to implement log() and exp() on small systems. See also cordic.
But depending on your requirements, piecewise linear or polynomial approximation of the overall function might be more appropriate. These just require a few multiplies and adds. It's also possible that \$\frac{1}{polynomial}\$ or \$\frac{1}{\sqrt{polynomial}}\$ would be a good fit for your function. These operations are similarly easy to add to the mix using Newton-Raphson.