Jump to content

Module:Math: Difference between revisions

259 bytes added ,  11 years ago
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 )
     if frame.args[1] == nil then
     local args = frame.args;
         return ''
   
    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 frame.args[i] ~= nil do
     while args[i] ~= nil do
         local val = z._cleanNumber( frame, frame.args[i] );
         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 )
     if frame.args[1] == nil then
     local args = frame.args;
         return ''
   
    if args[1] == nil then
         local parent = frame:getParent();
        args = parent.args;
     end
     end
     local min_value = nil;
     local min_value = nil;
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.