Module:Math: Difference between revisions
no edit summary
m>Dragons flight (adds expression checking, more error messages, and better handling of some precision format cases, and precision flooding check) |
m>Dragons flight No edit summary |
||
Line 4: | Line 4: | ||
-- Clean numeric value | -- Clean numeric value | ||
function z._cleanNumber( frame, number_string ) | function z._cleanNumber( frame, number_string ) | ||
if number_string == nil or number_string:len() == 0 then | |||
return nil, nil; | |||
end | |||
-- Attempt basic conversion | -- Attempt basic conversion | ||
local number = tonumber( number_string ) | local number = tonumber( number_string ) | ||
-- If failed, attempt to evaluate input as an expression | -- If failed, attempt to evaluate input as an expression | ||
if number == nil then | if number == nil then | ||
local attempt = frame:preprocess( '{{#expr: ' .. number_string .. '}}' ); | local attempt = frame:preprocess( '{{#expr: ' .. number_string .. '}}' ); | ||
attempt = tonumber( attempt ); | attempt = tonumber( attempt ); | ||
Line 101: | Line 105: | ||
-- Finds maximum argument | -- Finds maximum argument | ||
function z.max( frame ) | function z.max( frame ) | ||
local args = frame.args; | |||
if args[1] == nil then | |||
local parent = frame:getParent(); | |||
args = parent.args; | |||
end | end | ||
local max_value = nil; | local max_value = nil; | ||
local i = 1; | local i = 1; | ||
while | while args[i] ~= nil do | ||
local val = z._cleanNumber( frame, | local val = z._cleanNumber( frame, args[i] ); | ||
if val ~= nil then | if val ~= nil then | ||
if max_value == nil or val > max_value then | if max_value == nil or val > max_value then | ||
Line 122: | Line 129: | ||
-- Finds minimum argument | -- Finds minimum argument | ||
function z.min( frame ) | function z.min( frame ) | ||
local args = frame.args; | |||
if args[1] == nil then | |||
local parent = frame:getParent(); | |||
args = parent.args; | |||
end | end | ||
local min_value = nil; | local min_value = nil; |