Division algorithm: Difference between revisions

Content deleted Content added
Restored revision 1299849620 by Zinnober9 (talk): Invalid syntax, do NOT reinstate.
Pseudocode: I somewhat fixed the formatting of the pseudocode. It seems that Mathml is incompatible with all Wikipedia code formatting except "code" tags, but "code" tags aren't great for blocks (rather than inline). This seems the least of all evils.
Tag: Reverted
Line 276:
The following computes the quotient of {{var|N}} and {{var|D}} with a precision of {{var|P}} binary places:
 
<code>Express D as M × 2<sup>e</sup> where 1 &le; M < 2 (standard floating point representation)
<pre>
Express D' as:= MD ×/ 2<sup>e+1</sup> where ''// scale between 0.5 and 1, &le;can Mbe <performed 2with (standardbit floatingshift / pointexponent representation)subtraction''
N' := N / 2<sup>e+1</sup>
D' := D / 2<sup>e+1</sup> ''// scale between 0.5 and 1, can be performed with bit shift / exponent subtraction''
X := 48/17 − 32/17 × D' ''// precompute constants with same precision as D''
N' := N / 2<sup>e+1</sup>
{{nowrap|'''repeat''' <math>\left \lceil \log_2 \frac{P + 1}{\log_2 17} \right \rceil \,</math> '''times'''}} ''// can be precomputed based on fixed P''
X := 48/17 − 32/17 × D' ''// precompute constants with same precision as D''
{{nowrap|'''repeat''' <math>\left \lceil \log_2 \frac{P + 1}{\log_2 17} \right \rceil \,</math> '''times'''}} ''// can be precomputed based on fixed P''
X := X + X × (1 - D' × X)
'''end'''
'''return''' N' × X</code>
</pre>
 
For example, for a double-precision floating-point division, this method uses 10 multiplies, 9 adds, and 2 shifts.