Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 11 May 2007 21:16:27 -0400
CBFalconer wrote:
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 */
Correction - the c bit position is the log.
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
.
- References:
- Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- From: Tilmann Reh
- Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- From: CBFalconer
- Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- Prev by Date: Re: MicroSys SBC1190 Problems
- Next by Date: Re: Wireless USB Discussion Group
- Previous by thread: Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- Next by thread: Custom Software Development
- Index(es):
Relevant Pages
|