FANDOM


-- <nowiki>
local p = mw.clone(math)
 
-- @see [[Wikipedia:Clamping (graphics)]]
function p.clamp(x, min, max)
    return math.min(math.max(x, min), max)
end
 
-- @see [[Wikipedia:Wrapping (graphics)]]
function p.wrap(x, min, max)
    local tmp = x - math.modf((x - min) / (max - min)) * (max - min)
 
    return (tmp < 0) and (tmp + max - min) or tmp
end
 
-- @see <http://lua-users.org/wiki/SimpleRound>
function p.round(x, idp)
    local mult = 10 ^ (idp or 0)
 
    return math.floor(x * mult + 0.5) / mult
end
 
-- @see [[Wikipedia:Greatest common divisor]]
function p.gcd(a, b)
    if b == 0 then
        return a
    end
 
    return p.gcd(b, a % b)
end
 
-- @see [[Wikipedia:Least common multiple]]
function p.lcm(a, b)
    return math.abs(a * b) / p.gcd(a, b)
end
 
-- @see [[Wikipedia:Radian]]
function p.degrees(x)
    return x * (180 / math.pi)
end
 
-- @see [[Wikipedia:Radian]]
function p.radians(x)
    return x / (math.pi / 180)
end
 
-- @see <http://wiki.garrysmod.com/page/math/Remap>
function p.remap(x, oldMin, oldMax, newMin, newMax)
    return newMin + (x - oldMin) / (oldMax - oldMin) * (newMax - newMin)
end
 
return p
-- </nowiki>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.