Division algorithm: Difference between revisions

Content deleted Content added
Restored revision 1299915824 by Zinnober9 (talk): Revert, stripped tags.
Tags: Twinkle Undo Reverted
Undid revision 1300743975 by Zinnober9 (talk). edit conflict
Line 276:
The following computes the quotient of {{var|N}} and {{var|D}} with a precision of {{var|P}} binary places:
 
<div style="font-family: monospace, monospace;">
<pre>
Express D as M × 2<sup>e</sup> where 1 &le; M < 2 (standard floating point representation)<br>
D' := D / 2<sup>e+1</sup> ''// scale between 0.5 and 1, can be performed with bit shift / exponent subtraction''<br>
N' := N / 2<sup>e+1</sup><br>
X := 48/17 − 32/17 × D' ''// precompute constants with same precision as D''<br>
{{nowrap|'''repeat''' <math>\left \lceil \log_2 \frac{P + 1}{\log_2 17} \right \rceil \,</math> '''times'''}} ''// can be precomputed based on fixed P''<br>
X := X + X × (1 - D' × X)<br>
'''end'''<br>
'''return''' N' × X<br>
</prediv>
 
For example, for a double-precision floating-point division, this method uses 10 multiplies, 9 adds, and 2 shifts.