RosettaCodeData/Task/Exponentiation-operator/M2000-Interpreter/exponentiation-operator.m2000

31 lines
827 B
Plaintext

Module Exponentiation {
\\ a variable can be any type except a string (no $ in name)
\\ variable b is long type.
\\ by default we pass by value arguments to a function
\\ to pass by reference we have to use & before name,
\\ in the signature and in the call
function pow(a, b as long) {
p=a-a ' make p same type as a
p++
if b>0 then for i=1& to b {p*=a}
=p
}
const fst$="{0::-32} {1}"
Document exp$
k= pow(11&, 5)
exp$=format$(fst$, k, type$(k)="Long")+{
}
l=pow(11, 5)
exp$=format$(fst$, l, type$(l)="Double")+{
}
m=pow(pi, 3)
exp$=format$(fst$, m, type$(m)="Decimal")+{
}
\\ send to clipboard
clipboard exp$
\\ send monospaced type text to console using cr char to change lines
Print #-2, exp$
Rem Report exp$ ' send to console using proportional spacing and justification
}
Exponentiation