Labor of Division: Algorithm D
ridiculousfish.com
ridiculousfish.com
I don’t understand. Isn’t it possible for n to have the same number of digits as well? For example n=75, d=11. Or, if you like, computing 755 / 11: the problem reduces to computing 75 / 11 first. Why “exactly one more”?
q would be larger than one digit with certainty if we were working with chunks of size N+x (with x >= 2). N digits do not necessarily suffice, so N+1 is it, with the caveat that sometimes we have to drop back to the case of just N digits because q turned out to be longer than one digit.
An op unlovely as division
An op whose answer must be guessed
And then, through multiply, assessed;
An op for which we dearly pay,
In cycles wasted every day.
Division code is often hairy;
Long division's downright scary.
The proofs can overtax your brain,
The ceiling and floor may drive you insane.
Good code to divide takes a Knuthian hero
But even God can't divide by zero!
-- Henry S. Warren Jr.
Hacker's Delight
[1] https://ridiculousfish.com/blog/posts/labor-of-division-epis...