Module:Stdfunc

local s = {}

-- This is the Standard Function Library,              -- -- for some simple-yet-somehow-unimplemented functions. -- -- To Use: Type in                                     -- --                                                     -- ---local s = require("Module:stdfunc") --                                                     -- -- and to call the functions (e.g. tn), type            -- --                                                     -- ---s.tn(args)- --                                                     --

--Start of Number section-- function s.td(a,b) -- Conventional ToNumber: ToNumber with a fallback value return tonumber(a) or b end

function s.tn(a) -- Shorthand for s.td(a,0) return s.td(a,0) end

function s.t1(a) -- Shorthand for s.td(a,1) return s.td(a,1) end

function s.lu(a,b,c) -- Range Limit Number Value return math.min(math.max(a,b),c) end

function s.lut(a,b,c) -- Range Limit Number Test return a > b and a < c end

function s.tnl(a,b) -- ToNumber 0: Lower Limit given return math.max(s.tn(a),b) end

function s.tn0(a) -- Shorthand for s.tnl(a,0) return s.tnl(a,0) end

function s.div0(a,b) -- Division with div0 prevention return (b == 0) and a or (a / b) end

function s.rnd(a) -- Round Off function return math.ceil(a - 0.5) end

function s.rnds(a,b) -- Round Off with precision return s.rnd( a * 10 ^ b) / 10 ^ b end

function s.sfs(a,b) -- Round Off to Significant Figures return s.rnds(a,b-math.ceil(math.log10(math.abs(a)))) end --End of Number section--

--Start of String section-- function s.tt(a) -- Fallback String Value return a or "" end --End of String section--

return s