|z|=\sqrt{a2+b2}
The algorithm avoids performing the square and square-root operations, instead using simple operations such as comparison, multiplication, and addition. Some choices of the α and β parameters of the algorithm allow the multiplication operation to be reduced to a simple shift of binary digits that is particularly well suited to implementation in high-speed digital circuitry.
The approximation is expressed aswhere
Max
Min
For the closest approximation, the optimum values for
\alpha
\beta
\alpha0=
| ||||||
|
=0.960433870103...
\beta0=
| ||||||
|
=0.397824734759...
\alpha | \beta | Largest error (%) | Mean error (%) | |
---|---|---|---|---|
1/1 | 1/2 | 11.80 | 8.68 | |
1/1 | 1/4 | 11.61 | 3.20 | |
1/1 | 3/8 | 6.80 | 4.25 | |
7/8 | 7/16 | 12.50 | 4.91 | |
15/16 | 15/32 | 6.25 | 3.08 | |
\alpha0 | \beta0 | 3.96 | 2.41 |
When
\alpha<1
|z|
Max
Min
Max
|z|=max(Max,\alphaMax+\betaMin).
Depending on the hardware, this improvement can be almost free.
Using this improvement changes which parameter values are optimal, because they no longer need a close match for the entire interval. A lower
\alpha
\beta
Increasing precision: When splitting the line in two like this one could improve precision even more by replacing the first segment by a better estimate than
Max
\alpha
\beta
|z|=max(|z0|,|z1|),
|z0|=\alpha0Max+\beta0Min,
|z1|=\alpha1Max+\beta1Min.
\alpha0 | \beta0 | \alpha1 | \beta1 | Largest error (%) |
---|---|---|---|---|
1 | 0 | 7/8 | 17/32 | −2.65% |
1 | 0 | 29/32 | 61/128 | +2.4% |
1 | 0 | 0.898204193266868 | 0.485968200201465 | ±2.12% |
1 | 1/8 | 7/8 | 33/64 | −1.7% |
1 | 5/32 | 27/32 | 71/128 | 1.22% |
127/128 | 3/16 | 27/32 | 71/128 | −1.13% |
Beware however, that a non-zero
\beta0