RosettaCodeData/Task/Dot-product/M2000-Interpreter/dot-product.m2000
2023-07-01 13:44:08 -04:00

22 lines
700 B
Text

Module dot_product {
A=(1,3,-5)
B=(4,-2,-1)
Function Dot(a, b) {
if len(a)<>len(b) Then Error "not same length"
if len(a)=0 then Error "empty vectors"
object a1=each(a), b1=each(b)
// take type by first item in a()
long lowbound=dimension(a,1,0)
sum=a#val(lowbound)-a#val(lowbound)
While a1, b1 {sum+=array(a1)*array(b1)}
=sum
}
Print Dot(A, B)=3
Print Dot((1,3,-5), (4,-2,-1), 0)=3
dim k(2 to 4) as long long, z(3) as long long
k(2)=1,3,-5
z(0)=4,-2,-1
result=Dot(k(), z())
Print result=3, type$(result)="Long Long"
}
Module dot_product