Re: exact fixed-point inverse square root
- From: Terje Mathisen <terje.mathisen@xxxxxxxxxxxxx>
- Date: Sun, 06 Apr 2008 17:38:33 +0200
Nils wrote:
Hi usenet.
I'm looking for an algorithm to calculate the inverse square root of a fixed point integer.
I know about the Newton-Raphson iteration, but this one does not work if you're looking for an exact result because each step requires a multiplication which in fixed point math always goes along with a loss of precision.
Integer square roots can be calculated exact using a two bits per iteration algorithm.
For my application the Newton-Raphson iteration does not work. Even when I add more iterations than nessesary I always got biten by the precision loss. The bitwise calculation of the square-root (adopted to fixed point) followed by a division works well but is computational expensive.
I have never seen a inverse square root iteration that is not based on the Newton-Raphson iteration and I wonder why.
Even if it's not practical for real world applications because it's is to slow it would be nice to know how it works in principle.
I tried to come up with one of my own but failed. Any ideas?
Isn't this sort of trivial?
A fixed-point implementation is effectively identical to an integer-only, if you prescale the input, right?
So, by exact do you mean closest possible result, i.e. perfectly rounded, or do you mean largest possible value such that
res * res * input_value <= 1.0
i.e. truncated rounding?
Calculate an approximate result using table lookup + NR, then square it and multiply by the original number. The result should be very close to 1.0.
Depending upon the first step you can then adjust the first guess up or down by one ulp, then check which guess results in the best answer.
You can also do one extra iteration of the NR, using double-wide precision, then use the final error term to determine the correctly rounded result.
Terje
--
- <Terje.Mathisen@xxxxxxxxxxxxx>
"almost all programming can be viewed as an exercise in caching"
.
- References:
- exact fixed-point inverse square root
- From: Nils
- exact fixed-point inverse square root
- Prev by Date: exact fixed-point inverse square root
- Next by Date: Re: exact fixed-point inverse square root
- Previous by thread: exact fixed-point inverse square root
- Next by thread: Re: exact fixed-point inverse square root
- Index(es):
Relevant Pages
|
|