Re: rules of fixed-point arithmetic
- From: Anthony Williams <anthony.ajw@xxxxxxxxx>
- Date: Wed, 10 Sep 2008 21:47:55 +0100
ChrisQ <blackhole@xxxxxxxxxxx> writes:
Anthony Williams wrote:
Andrew Reilly <andrew-newspost@xxxxxxxxxxxxxxxxxxxxx> writes:
Yes, division of fixed point numbers is a pain, since, as you point
out, you have to deal with results that may not fit neatly into the
range of your data. Whenever possible, the answer is to just not
divide. When division is essential, you have to deal with it.
Having recently had to code some fixed point stuff (including
division) for an embedded platform, I can confirm that division is
indeed a real pain.
Anthony
For most embedded work, the general rule is to avoid anything to do
with the math lib, because of the code size impications and
expense.
Yes. Unfortunately the hardware was fixed, and we wanted to use a
math-heavy algorithm in order to improve on the prior
not-so-math-heavy-but-not-as-good algorithm.
Scaled integer is the usual route, arranging the data to suit
the range of expected values and to enable use of shift ^2 multiply /
divide to keep everything fast. The range of expected values is
usually quite well defined as are the accuracy
requirements. Everything else just becomes an error. What was the
problem with divide ?. Many modern cpus have integer divide
instructions, or you could even use one of the old bit shift divide
algorithms. Quite fast on a modern cpu, methinks.
If you look at the code to go with the DDJ article, you'll see that I
used a good old bit shift algorithm. It's not overly complicated, just
a pain compared to addition. It gets harder if the fixed point value
needs to have more bits than any of the available integer types, as
then you've got multi-word shifts and comparisons to handle too.
I looked at your ddj article btw and wonder why you used cordic,
rather than table lookup, perhaps with simple correction factors /
simple interpolation to improve the accuracy if needed ?. A 16 bit
lookup table is only 32 Kbytes for one quadrant, with reflection and
sign to get the others.
A lookup table with interpolation would have been another option. I
can't remember why we didn't use that, but CORDIC seemed better than
other algorithmic methods.
Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
.
- Follow-Ups:
- Re: rules of fixed-point arithmetic
- From: Terje Mathisen
- Re: rules of fixed-point arithmetic
- References:
- rules of fixed-point arithmetic
- From: Sam Green
- Re: rules of fixed-point arithmetic
- From: Andrew Reilly
- Re: rules of fixed-point arithmetic
- From: Nick Maclaren
- Re: rules of fixed-point arithmetic
- From: Andrew Reilly
- Re: rules of fixed-point arithmetic
- From: Nick Maclaren
- Re: rules of fixed-point arithmetic
- From: Andrew Reilly
- Re: rules of fixed-point arithmetic
- From: Anthony Williams
- Re: rules of fixed-point arithmetic
- From: ChrisQ
- rules of fixed-point arithmetic
- Prev by Date: Re: Fiber-optic supercomputer cluster node interconnect?
- Next by Date: Re: rules of fixed-point arithmetic
- Previous by thread: Re: rules of fixed-point arithmetic
- Next by thread: Re: rules of fixed-point arithmetic
- Index(es):
Relevant Pages
|