Long multiplication: Difference between revisions

→‎{{header|ATS}}: Code simplification and slight commentary revision.
(ATS added ahead of →‎{{header|AutoHotkey}})
(→‎{{header|ATS}}: Code simplification and slight commentary revision.)
Line 1,003:
I perform both binary long multiplication (designed for efficiency) and decimal arithmetic.
 
The example numbers, though fine for testing decimal arithmetic, are ''very'' bad for testing binary multiplication. TheyFor example, they never require a carry. So I have added (for binary multiplication) the example 79 228 162 514 264 337 593 543 950 335 squared equals 6 277 101 735 386 680 763 835 789 423 049 210 091 073 826 769 276 946 612 225. The first number is 96 one-bits.
 
<syntaxhighlight lang="ats">
Line 1,087:
w : &array (uint32, m + n),
i : size_t i,
k : uint64) (* carry *)
:<!refwrt> uint32void = (* carry *)
if i = m then
w[j + m] := u64u32 k
else
let
Line 1,102:
iloop (u, v, w, succ i, t >> 32)
end
val k = iloop (u, v, w, i2sz 0, zero64)
in
w[jiloop +(u, v, w, m]i2sz :=0, kzero64);
jloop (u, v, w, succ j)
end
Line 1,329 ⟶ 1,328:
w : &array (char, m + n),
i : size_t i,
k : intBtwe (0, 9)) (* carry *)
:<!refwrt> intBtwe (0, 9)void = (* carry *)
if i = m then
w[pred n - j] := bcd2char k
else
let
Line 1,355 ⟶ 1,354:
iloop (u, v, w, succ i, t_div_10)
end
val k = iloop (u, v, w, i2sz 0, 0)
in
w[prediloop n(u, -v, j]w, :=i2sz bcd2char0, k0);
jloop (u, v, w, succ j)
end
1,448

edits