Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 11 May 2007 15:14:14 -0400
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
.
- Follow-Ups:
- Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- From: CBFalconer
- Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- References:
- Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- From: Tilmann Reh
- Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- Prev by Date: Re: How to fix point?
- Next by Date: Re: state of PIC SRAM on boot
- Previous by thread: Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- Next by thread: Re: Simple/Fast Algorithm for binary logarithm in C (on ARM7)
- Index(es):
Relevant Pages
|