Task

Explicitly implement   long multiplication.

This is one possible approach to arbitrary-precision integer algebra.



For output, display the result of    264 * 264.

Optionally, verify your result against builtin arbitrary precision support.

The decimal representation of    264    is:

18,446,744,073,709,551,616

The output of    264 * 264    is    2128,    and is:

340,282,366,920,938,463,463,374,607,431,768,211,456



data b, c, v;
integer d, e, i, j, s;
 
b = 1.argv;
b.dump(',');
v = 2.argv;
v.dump(',');
 
c.run(~b + ~v + 1, 0);
 
for (i, d in b) {
    b[i] = d - '0';
}
 
for (j, d of v) {
    d = v[j] - '0';
 
    s = 0;
    for (i, e of b) {
        s += e * d + c[i + j];
        c[i + j] = s % 10;
        s /= 10;
    }
    while (s) {
        s += c[i + j];
        c[i + j] = s % 10;
        s /= 10;
        i -= 1;
    }
}
 
c.delete(-1);
c.bf_drop0("");
 
for (i, d in c) {
    c[i] = d + '0';
}
 
o_form("~\n", c);