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.
If
x = q × ln(2) + r
thenThis means that if you can find
q
andr
it will be easy to find the exponent, you just need to bit shift 2 (2<<(q-1)
) findexp(r)
and multiply them together.To find
q
andr
first note ln(2)=0.6931471805599453. If you have division availableif you don't have division you can use a loop