Module:Math: Difference between revisions

add "sum" per merge with Module:Sum
en>Primefac
(add log10 functionality from module merge)
en>Primefac
(add "sum" per merge with Module:Sum)
Line 244:
if min_value then
return min_value
end
end
 
--[[
sum
 
Finds the sum
 
Usage:
{{#invoke:Math| sum | value1 | value2 | ... }}
OR
{{#invoke:Math| sum }}
 
Note, any values that do not evaluate to numbers are ignored.
]]
 
function wrap.sum(args)
return p._sum(unpackNumberArgs(args))
end
 
function p._sum(...)
local sums, count = fold((function(a, b) return a + b end), ...)
if not sums then
return 0
else
return sums
end
end
Anonymous user