Guest User

Untitled

a guest
Dec 10th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. DivInteger := proc(num1::list, num2::list)
  2. local d, n1, n2, u, j, q, r, m, n, w;
  3. if StripZeroes(num2) = [0] then error "Can't divide zero"; end if; # Prevent division by zero
  4. q := [];
  5. n := nops(num2);
  6. m := nops(num1) - n;
  7. d := floor(10/(op(1,num2) + 1)); # Get the normalization factor
  8. n1 := MultInteger(num1, [d]); # Normalize
  9. n2 := MultInteger(num2, [d]);
  10. u := [op(1..n + 1, n1)];
  11. for j from -(m) to -1 do
  12. if op(1, u) = op(1, n2) then
  13. q := [op(q), 9];
  14. else
  15. q := [op(q), floor((op(1, u)*10 + op(2, u)) / op(1, n2))];
  16. end if;
  17. w := MultInteger([op(-1, q)], n2);
  18. while CompInt(w, u) = 1 do
  19. q := subsop(-1 = (op(-1, q) - 1), q);
  20. w := SubInteger(w, n2);
  21. end do;
  22. r := SubInteger(u, w);
  23. if j < -1 then
  24. u := AddInteger(MultInteger(r, [1,0]), [op(j + 1, n1)]);
  25. end if
  26. end do;
  27. r := op(1, ShortDiv(r, d));
  28. return [q, r];
  29. end proc:
Add Comment
Please, Sign In to add comment