Sum and product of an array: Difference between revisions
Content added Content deleted
m (useless in Fortran) |
|||
Line 2,364: | Line 2,364: | ||
foldl op+ 0.0 x; |
foldl op+ 0.0 x; |
||
foldl op* 1.0 x;</lang> |
foldl op* 1.0 x;</lang> |
||
=={{header|Stata}}== |
|||
Mata does not have a builtin product function, but one can do the following, which will compute the product of nonzero elements of the array: |
|||
<lang stata>a = 1,-2,-3,-4,5 |
|||
sum(a) |
|||
-3 |
|||
(-1)^mod(sum(a:<0),2)*exp(sum(log(abs(a)))) |
|||
-120</lang> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |