Square Root and Inverse Square Root Approximations
by Iain Paterson Stephens
It is often necessary to be able
to calculate the square root or inverse square root of a non-negative
floating-point number to a high degree of accuracy. This may be used,
for example, when calculating the magnitude of the output from an FFT
or for Feedforward Automatic Gain Control. A simple, effective and fast
algorithm for this is based on the Newton-Raphson iteration method. For
example, the inverse square root 'x' of the floating point number 'y'
can be calculated as follows:
if x = 1/sqrt(y)
Step
1: Give Give an initial approximation for xn the inverse square root.
Step 2:
Use the initial approximation,xn, in the Newton-Raphson
iteration, as follows:-
xn+1 =
(0.5xn)(3-y(xn)2)
Step 3:
Repeat the Newton-Raphson iteration, this time replacing the input
value xn, with the calculated 'second' approximation xn+1.
Step 4: Repeat step 3 a number of times according to the required accuracy,
for example only two iterations are required for an accuracy down to
+/- 1 LSB for an IEEE 32-bit floating point number.
And what
about calculating x = srqt(y)?
To calculate the square root, just use,
x
= y.(1/sqrt(y))
that is, try using the inverse square root approximation first and
then multiply the result by the original number.
|