How to calculate arbitrary power / root?

I have an application that should raise a number to a fractional power. The target platform is the FPGA, and I can get estimates for the size of the FPU for it, but I need an algorithm to increase the number to fractional power just for a feasibility study. I assume that in the worst case, I expect that in practice we can use short abbreviations, but for now I want to show that the worst case can be implemented on our part.

I think I will ask here and see if there are any general methods that I could test. I know that there are programmatic methods for this, I only want a reasonably efficient algorithm to get started. I will worry about the implementation of FPGA.

+6
math floating-point algorithm exponent
Sep 03 '09 at 21:05
source share
2 answers

Is your input range arbitrary or known in a certain range?

anyway x m = exp (m log x), so if you can create functions to evaluate exp (x) and log (x) and multiply, you're probably done.

You need to figure out how you want to handle nonpositive x values.

(hint for log (x): if it is an IEEE-754 floating point , shift the value, if necessary, until you get a range of numbers between 2 k and 2 k + 1 for some value of K. This allows you to deal with range of 2: 1, which is not too difficult to approximate by polynomials, then you have only a small number of possibilities for processing the exponent and shift number.

Corresponding hint for exp (x): write x = k + b, where 0 <= b <1, and k is an integer. Then exp (x) = exp (k) * exp (b); b has a limited range, and k has a limited number of discrete possibilities.)

(hint # 2: numbers probably work better for x m = g (mf (x)), where f (x) = log 2 x and g (x) = 2 x .)

+7
03 Sep '09 at 21:15
source share
β€” -

As Jason S. said, this is done using the identity x m = exp (m log x). In practice, however, you will have to deal with truncation errors. I think this is usually done

  • Use this identity: x m = (2 n * x / 2 n ) m = 2 nm * (x / 2 n ) m and find an integer n such that 1 <= x / 2 n <2.
  • Calculate t = log2 (x / 2 n ). This can be done either using a sufficiently high degree of Taylor expansion, or with a good ol 'Newton-Raphson. You must make sure that the maximum error in the interval [1, 2] is not too large for you.
  • Calculate u = nm + tm.
  • Our goal is to calculate 2 u . Use the fact that 2 u = 2 v * 2 uv and find an integer v such that 0 <= u- v <1.
  • Calculate w = 2 uv again using our friend Taylor or Newton-Raphson. The interval of interest is 0 <= uv <1.
  • Now your answer is 2 v * w.
+5
Sep 03 '09 at 21:55
source share



All Articles