http://d.puremagic.com/issues/show_bug.cgi?id=4725



--- Comment #15 from bearophile_h...@eml.cc 2011-11-25 01:04:35 PST ---
A good signature for sum():

sum(sequence[, dim=0[, start]])

In Fortran's sum() 'dim' is an optional value that defaults to 0 (well to the
first index of an array, that is 0 in D), it specifies what dimension to perfom
the sum to. On default it acts like the Python sum().

In Fortran you often have arrays of vectors (or arrays of tuples in D), and
Fortran supports vector operations similar to D ones, so:

VA = [[1,2,3], [4,5,6]]

sum(VA)    ==> [5, 7, 9]
sum(VA, 0) ==> [5, 7, 9]
sum(VA, 1) ==> [6, 15]
sum(VA, x) ==> Error if x > 1

Example usage, points is an array of double[3] that represent 3D points:

totalDistance = sqrt(sum(points[] ^^ 2, dim=0));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to