Module:Math: रिवीजन सभ के बीचा में अंतर

Content deleted Content added
get #expr without a frame, don't make unnecessary wrappers, and lazily initialise dependent modules, per protected edit request by User:Jackmcbarn
simplify using a new binary_fold function, per protected edit request by User:Esquivalience
लाइन 49:
end
 
local function applyFuncToArgsfold(func, ...)
-- 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.
लाइन 63:
end
return ret, count
end
 
--[[
Fold arguments by selectively choosing values (func should return when to choose the current "dominant" value).
]]
local function maxOfTwobinary_fold(afunc, b...)
local value = fold((function(a, b) if func(a, b) then return a else return b end end), ...)
return a + bvalue
end
 
Line 190 ⟶ 198:
return result
end
 
 
--[[
Line 207 ⟶ 216:
 
function p._max(...)
local max_value = binary_fold((function(a, b) return a > b end), ...)
local function maxOfTwo(a, b)
if a > b then
return a
else
return b
end
end
local max_value = applyFuncToArgs(maxOfTwo, ...)
if max_value then
return max_value
Line 239 ⟶ 241:
 
function p._min(...)
local min_value = binary_fold((function(a, b) return a < b end), ...)
local function minOfTwo(a, b)
if a < b then
return a
else
return b
end
end
local min_value = applyFuncToArgs(minOfTwo, ...)
if min_value then
return min_value
Line 270 ⟶ 265:
 
function p._average(...)
local functionsum, getSumcount = fold((function(a, b) return a + b end), ...)
return a + b
end
local sum, count = applyFuncToArgs(getSum, ...)
if not sum then
return 0
Line 362 ⟶ 354:
return oldr
end
local result, count = applyFuncToArgsfold(findGcd, ...)
return result
end
"https://bh.wikipedia.org/wiki/Module:Math" से लिहल गइल