Radix-4 SRT division returns the exact quotient and remainder full
This proof shows: correctness.
Setting. x,d∈[1/2,1), radix 4, digits qj∈{−2,…,2}, ρ=2/3. Write yj=4wj−1. The divisor estimate d^=⌊16d⌋/16 and the remainder estimate y^j=⌊8yj⌋/8 satisfy d^≤d<d^+1/16 and y^j≤yj<y^j+1/8. A cell is the set C(d^,y^)={(y,d):d^≤d<d^+161, y^≤y<y^+81, ∣y∣≤4ρd}.
Table condition (T). For every nonempty cell the table digit k satisfies, for all (y,d) in the cell, y≥(k−ρ)d unless k=−2, and y≤(k+ρ)d unless k=2. The implementation checks (T) by evaluating the two linear functions at the corners of each cell in exact rationals; a linear function on a box attains its extremes at corners, and the strict upper edges only make the check conservative.
Lemma 1 (invariant). Under (T), ∣wj∣≤ρd for j=0,…,n.
Proof. w0=x/4<1/4, and ρd≥32⋅21=31. Suppose ∣wj−1∣≤ρd. Then ∣yj∣≤4ρd, so (yj,d) lies in the cell C(d^,y^j), which is therefore nonempty, and the digit k=qj read from the table satisfies (T) at (yj,d). If k=−2 then wj=yj−kd≥−ρd; if k=−2 then wj=yj+2d≥−4ρd+2d=−32d=−ρd. Symmetrically wj≤ρd, using yj≤4ρd when k=2: wj≤38d−2d=ρd. □
Lemma 2 (series). 4dx=∑j=1nqj4−j+4ndwn.
Proof. From wj=4wj−1−qjd, dividing by 4jd gives 4j−1dwj−1=qj4−j+4jdwj. Summing from j=1 to n telescopes to the claim, since w0/d=x/(4d). □
Theorem. After line L7, Q=⌊x4n−1/d⌋ and 0≤w<d, with 4dx=Q4−n+w4−n/d.
Proof. Line L6 accumulates Q=∑j=1nqj4n−j, an integer. By Lemma 2, x4n−1/d=Q+wn/d, and by Lemma 1, wn/d∈[−32,32]. If wn≥0 then wn/d∈[0,1) and Q is the floor. If wn<0, line L7 replaces (Q,wn) by (Q−1,wn+d), which keeps Q+w/d unchanged and puts w/d∈[31,1); again Q is the floor. □
Corollary (correct rounding). Let a=ma2ea, b=mb2eb with ma,mb∈[1/2,1) binary64 significands, n=28, and suppose a/b is a normal number. Then Q=⌊(ma/mb)254⌋ lies in [253,255), and ma/mb=(Q+θ)2−54 with θ∈[0,1) and θ=0 iff w=0. Let Q=K2s+R with 0≤R<2s and K of exactly 53 bits (s∈{1,2}). The exact value lies in (K+(R+θ)2−s)2s−54, and round to nearest, ties to even, picks K+1 iff (R+θ)2−s>1/2, or =1/2 and K is odd. Since R is an integer and θ∈[0,1), (R+θ)2−s>1/2 iff R>2s−1, or R=2s−1 and θ>0; and =1/2 iff R=2s−1 and θ=0. This is exactly the test in srt_float_divide, and the scaling by 2ea−eb is exact for a normal result. □