42 lines
1.2 KiB
Text
42 lines
1.2 KiB
Text
$ include "seed7_05.s7i";
|
|
|
|
const func string: (in string: a) * (in string: b) is func
|
|
result
|
|
var string: product is "";
|
|
local
|
|
var integer: i is 1;
|
|
var integer: j is 1;
|
|
var integer: k is 0;
|
|
var integer: carry is 0;
|
|
begin
|
|
if startsWith(a, "-") then
|
|
if startsWith(b, "-") then
|
|
product := a[2 ..] * b[2 ..];
|
|
else
|
|
product := "-" & a[2 ..] * b;
|
|
end if;
|
|
elsif startsWith(b, "-") then
|
|
product := "-" & a * b[2 ..];
|
|
else
|
|
product := "0" mult length(a) + length(b);
|
|
for i range length(a) downto 1 do
|
|
k := i + length(b);
|
|
carry := 0;
|
|
for j range length(b) downto 1 do
|
|
carry +:= (ord(a[i]) - ord('0')) * (ord(b[j]) - ord('0')) + (ord(product[k]) - ord('0'));
|
|
product @:= [k] chr(carry rem 10 + ord('0'));
|
|
carry := carry div 10;
|
|
decr(k);
|
|
end for;
|
|
product @:= [k] chr(ord(product[k]) + carry);
|
|
end for;
|
|
while startsWith(product, "0") and length(product) >= 2 do
|
|
product := product[2 ..];
|
|
end while;
|
|
end if;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
begin
|
|
writeln("-18446744073709551616" * "-18446744073709551616");
|
|
end func;
|