DSP: Power of Two Approximation
Posted
#1
(In Topic #288)
Regular

Fixed point exponentiation
The following program shows how to calculate an approximation of two raised to a float value. The argument is assumed to be positive.
Code (gambas)
- ' Gambas module file
- '========================================================================
- v = 1 / 32
- Lookup_V.Add(v)
- Lookup_L.Add(ev)
- Print v, ev
- v += 1 / 16
- '========================================================================
- f = x - n
- v = Ln2 * f
- y = v - Lookup_V[bbbb]
- ey = 1 + y * (1 + y * (1 / 2 + y / 6))
- '========================================================================
Here is the output:
Code
0.03125 1.0317434074991
0.09375 1.09828514030783
0.15625 1.1691184461695
0.21875 1.2445201077661
0.28125 1.32478475872887
0.34375 1.41022603492571
0.40625 1.50117780000012
0.46875 1.59799544995063
0.53125 1.7010573018484
0.59375 1.81076607211939
0.65625 1.92755045016754
0.71875 2.05186677348798
0.002823590279973 1.00282758036558 1.00282758036293
1.4142135623731 1.4142135623731 1.41421356236936
.... and carry a big stick!
1 guest and 0 members have just viewed this.



