Content deleted Content added
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;">
Express D as M × 2<sup>e</sup> where 1 ≤ 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>
'''end'''<br>
'''return''' N' × X<br>
</
For example, for a double-precision floating-point division, this method uses 10 multiplies, 9 adds, and 2 shifts.
|