Skip to content

Instantly share code, notes, and snippets.

@kt3k
Created April 20, 2013 06:39
Show Gist options
  • Save kt3k/5425013 to your computer and use it in GitHub Desktop.
Save kt3k/5425013 to your computer and use it in GitHub Desktop.
div implementation in ALGOL60
integer procedure div(a, b); value a, b;
integer a, b;
if b = 0 then
fault( `div by zero' , a)
else
begin integer q, r;
q := 0; r := iabs(a);
for r := r - iabs(b) while r ≥ 0 do q := q + 1;
div := if a < 0 ≡ b > 0 then -q else q
end div;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment