How can I calculate Exponential using CORDIC for numbers outside [-1, 1]?

2.6k Views Asked by At

I am not able to understand the math behind calculating exponential of a number outside the range [-1, 1) (actually I am not sure what is a good range to compute exp using CORDIC, some place I read [-pi/4, pi/4] and in others I have read [-1, 1)) using CORDIC algorithm. Can someone give an example?

I read following statement at http://zone.ni.com/reference/en-XX/help/371599G-01/lvfpga/ht_exponential/:

"x must be in the range [–1, 1). To compute exp(x) when x is outside this range, find an integer q and a real number r, where r is in the range [0, ln(2)), such that x = q × ln(2) + r. You then can compute 2^q × exp(r), which is equivalent to exp(x). Because r is in the valid range of [–1, 1), you can use this function to compute exp(r)."

But it doesn't make much sense to me as to how can I find q and r?

Second approach I found was at http://www.xilinx.com/support/documentation/application_notes/xapp552-cordic-floating-point-operations.pdf which tells us to use to equations after dividing the number into integer and fraction part:

cosh(int + frac) = cosh(int) * cosh(frac) + sinh(int) * sinh(frac)
sinh(int + frac) = cosh(int) * sinh(frac) + cosh(frac) * sinh(int)

cosh(int) and sinh(int) are taken from lookup table. But this approach is more computationally intensive so I prefer the previous one.

1

There are 1 best solutions below

0
On

If x = q × ln(2) + r then

exp(x) = exp(q × ln(2) + r)
       = exp(ln(2))^q exp(r)
       = 2^q exp(r)

This means that if you can find q and r it will be easy to find the exponent, you just need to bit shift 2 (2<<(q-1)) find exp(r) and multiply them together.

To find q and r first note ln(2)=0.6931471805599453. If you have division available

q =  floor( x / ln(2) )
r = x - q * ln(2)

if you don't have division you can use a loop

q = 0
while( x > ln(2) ) {
    x -= ln(2)
    ++q
}
r = x