Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)



Tilmann Reh wrote:

in a current ARM7 project I need to do some calculations which
include a logarithm. All other math is done with integers (i.e.
fixed point arithmetic), and I would like to calculate the log
fast and with little code - so I don't prefer using FP conversion
and the standard math libraries.

Can anyone point to fixed-point logarithmic routines I could use
(resp. tailor to my needs)?

If you are using integers the logs are also integers. The bit
position of the most significant bit gives the binary log. If you
wish you can also round it up if the next two bits are 11. This is
probably about as good as you can do in integers.

You can extract this with (untested)

while (b = c & (c - 1)) do c = b;
/* now c is the log2 of the original c value */

It may be worthwhile to test for a zero value before starting this.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages