Dot product: Difference between revisions
Content deleted Content added
m →JS ES6 |
|||
Line 1,911:
=={{header|M2000 Interpreter}}==
Version 12 can use types for arrays (earlier versions use variant type by default).
So we can adjust the return value of Dot() to be the same as the first item of first array. All functions of M2000 return variant type (including objects) or array of variant values, for multiple values (which is an object too).
<syntaxhighlight lang="m2000 interpreter">
Module dot_product {
Line 1,918 ⟶ 1,922:
if len(a)<>len(b) Then Error "not same length"
if len(a)=0 then Error "empty vectors"
// 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
|