Jump to content

Long multiplication: Difference between revisions

added Ursala
No edit summary
(added Ursala)
Line 777:
340282366920938463463374607431768211456
340282366920938463463374607431768211456</pre>
 
=={{header|Ursala}}==
 
Natural numbers of unlimited size are a built in type,
and arithmetic operations on them are available as library functions.
However, since the task calls for explicitly implementing long
multiplication, here is an implementation using nothing but language
primitives. The numbers are represented as lists of booleans,
LSB first. The compiler already knows how to parse and display
them in decimal.
 
<lang Ursala>successor = ~&a^?\1! ~&ah?/~&NfatPRC ~&NNXatPC
 
sum = ~&B^?a\~&alrY ~&B?abh/successor@alh2fabt2RC ~&Yabh2Ofabt2RC
 
product = ~&alrB^& sum@NfalrtPXPRCarh2alPNQX
 
x = 18446744073709551616
 
#show+
 
y = %nP product@iiX x</lang>
output:
<pre>340282366920938463463374607431768211456</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.