How to calculate a logarithm or an exponential without using multiplies
Pretty nifty stuff. The author iterates through a lookup table with addition, subtraction, and bit-shifts to compute 32-bit fixed point exponentials and logarithms for base e (can easily be converted into other bases too) . Additionally includes some notes on residual error.
There is some confusion in the section on logarithms. The C code example initializes y = 0xA65AF, which in 16-bit integer 16-bit fraction (16.16) is about 10.39721. Why? Because e^10.39721 is about 32,768, and the algorithm requires that we divide x by something to make it smaller than zero. Thus, it cannot compute ln(x) for x>32767.
The author also says that x is in 16.16 format, but then treats x as if it were in 1.31, and x is never divided by 32,768! Why? It turns out that treating a 16.16 number as if it were 1.31 is the same as dividing by 32,768!
Finally, by adjusting the lookup table, exponentials and logarithms for other bases (2, 10, pi, whatever) can be computed as well.
Thoughts of a random geek
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment