Long multiplication: Difference between revisions
m
→{{header|RPL}}: typos
(add RPL) |
m (→{{header|RPL}}: typos) |
||
Line 6,184:
=={{header|RPL}}==
To solve the task, we need to develop part of a BigInt library
{| class="wikitable"
! RPL code
Line 6,231:
≫ ≫ ‘<span style="color:blue">MULbig’ STO
|
<span style="color:blue">NoZero</span> ''( "0..0xyz"
count leading zeros
keep the rest
<span style="color:blue">ZeroFill</span> ''( "xyz" n
<span style="color:blue">Swap→Zero</span> ''( a b →
swap a and b if length(a) < length(b)
return length difference
<span style="color:blue">ADDbig</span> ''( "a" "b"
res = "" ; carry = 0
for j = length(a) downto 1 step 10
Line 6,251:
if b > 1E10 then digits -= 1E10 ; carry = 1
convert digits to 10-char string with leading zeros
next j
prepend carry and remove leading zeros
<span style="color:blue">DigitMul</span> ''( "a" d
res = "" ; carry = 0
for j = length(a) downto 1
Line 6,261:
carry = digit // 10
digit %= 10
next j
prepend carry
<span style="color:blue">MULbig</span> ''( "a" "b"
sum = "0" ; for j = length(b) downto 1
tmp = a * b[j]
shift left tmp length(b)-j times, then add to sum
next j
|}
Line 6,277:
1: "340282366920938463463374607431768211456"
</pre>
=={{header|Ruby}}==
{{trans|Tcl}}
|