Goldschmidt division with a final exact correction returns the correctly rounded quotient full
This proof shows: correctness.
Setting. The algorithm of the page, for positive normal binary64 numbers a=A⋅2ea and b=B⋅2eb with A,B∈[1,2) and a normal quotient (signs are handled separately and are exact). The iteration works with integers scaled by 2−W, W=64; every product is truncated toward zero to W fractional bits. Write tr(x) for this truncation, so 0≤x−tr(x)<2−W for x≥0. The seed f0 is 1/ci rounded to 10 fractional bits, where ci=1+(i+21)/27 and i=⌊(B−1)27⌋. The number of iterations is k≥3. Let Q=A/B∈(21,2) and let v=2−52 if A≥B and v=2−53 otherwise, so that v is the spacing of binary64 numbers at Q.
Theorem. The returned value is RN(a/b), the binary64 number nearest to a/b.
Lemma 1 (seed). ∣1−Bf0∣<2−7.
Proof. ∣B−ci∣≤2−8 and ci≥1, so ∣1−B/ci∣≤2−8. Rounding gives ∣f0−1/ci∣≤2−11, so ∣Bf0−B/ci∣≤2⋅2−11. Hence ∣1−Bf0∣≤2−8+2−10<2−7. ■
Lemma 2 (convergence with truncation). Let dj=1−ηj and nj=Qdj+τj after line L3 (j=0) and after the j-th pass of lines L5 and L6. Then ∣η0∣<2−7+2−64, 0≤ηj+1<ηj2+2−W, and ∣τj∣<(j+1)⋅21−W(1+2−6)j.
Proof. Line L3 gives d0=Bf0−β0 and n0=Af0−α0 with 0≤α0,β0<2−W, so η0=(1−Bf0)+β0, which with Lemma 1 gives the first claim, and τ0=n0−Qd0=Qβ0−α0, so ∣τ0∣<2⋅2−W as Q<2.
Line L5 sets fj=2−dj=1+ηj exactly. Line L6 gives dj+1=djfj−β=(1−ηj)(1+ηj)−β=1−ηj2−β, so ηj+1=ηj2+β∈[0,ηj2+2−W). It also gives nj+1=njfj−α=Qdjfj+τjfj−α=Q(dj+1+β)+τjfj−α, so τj+1=τjfj+Qβ−α and ∣τj+1∣<∣τj∣(1+∣ηj∣)+21−W. Since ∣ηj∣<2−6 for all j, induction gives the bound on τj. ■
Lemma 3 (accuracy after three iterations). For 3≤k≤64, ∣nk−Q∣<2−54.
Proof. From Lemma 2, η1<(2−7+2−64)2+2−64<2−13.9, η2<2−27.8+2−64<2−27.7 and η3<2−55.4+2−64<2−55.3; for j≥3, ηj+1<ηj2+2−64<2−55.3 as well. For τ, Lemma 2 gives ∣τ3∣<4⋅2−63(1+2−6)3<2−60.9, and for j≥3 the recurrence ∣τj+1∣<∣τj∣(1+2−55)+2−63 gives ∣τk∣<2−60.9(1+2−49)+61⋅2−63<2−56.9 for k≤64. Then ∣nk−Q∣≤Qηk+∣τk∣<2⋅2−55.3+2−56.9<0.82⋅2−54+0.14⋅2−54<2−54. ■
Proof of the theorem. Let q∗ be the integer nearest to Q/v. By the no-midpoint property of quotients (a binary quotient A/B of p-bit significands is never the midpoint of two consecutive p-bit numbers, see floating-point division), Q/v is not a half-integer, so q∗ is unique and ∣Q/v−q∗∣<21.
Line L7 rounds nk/v to the nearest integer q, so ∣q−nk/v∣≤21. By Lemma 3, ∣nk−Q∣/v<2−54/2−53=21. Hence ∣q−Q/v∣<1, and q∈{q∗−1,q∗,q∗+1}.
Line L8 tests Q<(q−21)v, that is 2Ma2s<(2q−1)Mb with A=Ma2−52, B=Mb2−52 and v=2−s, exactly in integers. It holds if and only if q>q∗, that is q=q∗+1, and then it decrements q to q∗. Line L9 tests Q>(q+21)v, which holds if and only if q<q∗, and increments q. After both lines q=q∗.
Finally q∗v=RN(Q): Q∈[1,2) with v=2−52 or Q∈(21,1) with v=2−53, so the binary64 numbers near Q are exactly the multiples of v (and q∗v may be the power of two at the top of the binade, which is also a binary64 number). Line L10 multiplies by 2ea−eb, which is exact when the result is normal, so it returns RN(Q)2ea−eb=RN(a/b). Ties never occur, so the result is the same for ties-to-even and ties-away. ■
Remarks. The correctness of the result rests on lines L8 and L9 and on Lemma 3; the iteration itself needs no rounding analysis beyond Lemma 2. With k=2 the bound of Lemma 3 is only about 2−26, the correction can be off by many units, and the tests confirm that the result is then often wrong. Hardware implementations replace the exact integer comparisons by the sign of a remainder a−qb computed with a multiplier, which is the same test.