Module:Math: Difference between revisions
m
1 revision imported from wikipedia:Module:Math: ADDING TEMPLATES. AGAIN
(typo fix) |
m (1 revision imported from wikipedia:Module:Math: ADDING TEMPLATES. AGAIN) |
||
(One intermediate revision by the same user not shown) | |||
Line 52:
-- Use a function on all supplied arguments, and return the result. The function must accept two numbers as parameters,
-- and must return a number as an output. This number is then supplied as input to the next function call.
local vals = makeArgArray(...)
local count = #vals -- The number of valid arguments
if count == 0 then return
-- Exit if we have no valid args, otherwise removing the first arg would cause an error.
nil, 0
end
local ret = table.remove(vals, 1)
for _, val in ipairs(vals) do
Line 120:
else
return p._order(input_number)
end
end
Line 154:
return math.log10(denom_value);
end
end
end
end
input_number, input_string = p._cleanNumber(input_string);
Line 163:
else
return p._precision(input_string)
end
end
Line 180:
x = string.sub(x, 1, exponent_pos - 1)
result = result - tonumber(exponent)
end
if decimal ~= nil then
Line 238:
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
Line 254:
--[[
min
Finds the minimum argument
Line 279:
--[[
sum
Finds the sum
Line 305:
--[[
average
Finds the average
Line 347:
else
return p._round(value, precision)
end
end
Line 387:
else
return p._mod(x, y)
end
end
Line 431:
precision_format
Rounds a number to the specified precision and formats according to rules
originally used for {{template:Rnd}}. Output is a string.
Line 463:
-- some circumstances because the terminal digits will be inaccurately reported.
if order + precision >= 14 then
if order + orig_precision >= 14 then
precision = 13 - order;
end
end
Line 472 ⟶ 473:
value = p._round(value, precision)
current_precision = p._precision(value)
end
local formatted_num = lang:formatNum(math.abs(value))
Line 482 ⟶ 483:
else
sign = ''
end
-- Handle cases requiring scientific notation
Line 491 ⟶ 492:
formatted_num = lang:formatNum(math.abs(value))
else
order = 0;
end
formatted_num = sign .. formatted_num
-- Pad with zeros, if needed
if current_precision < precision then
local padding
Line 509 ⟶ 510:
formatted_num = formatted_num .. string.rep('0', padding)
end
else
padding = precision - current_precision
if padding > 20 then
Line 526 ⟶ 527:
else
order = lang:formatNum(order)
end
formatted_num = formatted_num .. '<span style="margin:0 .15em 0 .25em">×</span>10<sup>' .. order .. '</sup>'
Line 535 ⟶ 536:
--[[
Helper function that interprets the input numerically. If the ▼
▲Helper function that interprets the input numerically. If the
input does not appear to be a number, attempts evaluating it as
a parser functions expression.
|