Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. Read the Privacy Policy to learn what information we collect about you and how we use it.
If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision |
Your text |
Line 219: |
Line 219: |
| if max_value then | | if max_value then |
| return max_value | | return max_value |
| end
| |
| end
| |
|
| |
| --[[
| |
| median
| |
|
| |
| Find the median of set of numbers
| |
|
| |
| Usage:
| |
| {{#invoke:Math | median | number1 | number2 | ...}}
| |
| OR
| |
| {{#invoke:Math | median }}
| |
| ]]
| |
|
| |
| function wrap.median(args)
| |
| return p._median(unpackNumberArgs(args))
| |
| end
| |
|
| |
| function p._median(...)
| |
| local vals = makeArgArray(...)
| |
| local count = #vals
| |
| table.sort(vals)
| |
|
| |
| if count == 0 then
| |
| return 0
| |
| end
| |
|
| |
| if p._mod(count, 2) == 0 then
| |
| return (vals[count/2] + vals[count/2+1])/2
| |
| else
| |
| return vals[math.ceil(count/2)]
| |
| end | | end |
| end | | end |
Line 275: |
Line 244: |
| if min_value then | | if min_value then |
| return min_value | | 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 |
| end | | end |
Line 361: |
Line 304: |
|
| |
|
| Usage: | | Usage: |
| {{#invoke:Math | log10 | x }} | | {{#invoke:Math | log | x }} |
| ]] | | ]] |
|
| |
|