Looks sensible to me. Minor observations:
- It will blow up with a division by zero if z = 0, however, that's probably the correct behaviour.
- The two checks for overflow are clever - if we overflow, then we have definitely exceed our invariant, and so need to do the reduce step.
- I've suggested recording one extra invariant above.
- I've run a few different versions of this test code, and it has always produced the correct answers, so I think it is working fine.