Skip to main content

Applications of the math Library

FunctionDescriptionExampleResult
piPimath.pi3.1415926535898
absAbsolute valuemath.abs(-2012)2012
ceilRound upmath.ceil(9.1)10
floorRound downmath.floor(9.9)9
maxMaximum of argsmath.max(2,4,6,8)8
minMinimum of argsmath.min(2,4,6,8)2
powx to the y powermath.pow(2,16)65536.0
sqrtSquare rootmath.sqrt(65536)256.0
modfInteger and fraction partsmath.modf(20.12)20 0.12
randomseedSet random seedmath.randomseed(os.time())
randomRandom numbermath.random(5,90)5~90
radDegrees to radiansmath.rad(180)3.1415926535898
degRadians to degreesmath.deg(math.pi)180.0
expe to the xmath.exp(4)54.598150033144
logNatural log of xmath.log(54.598150033144)4.0
log10Base-10 log of xmath.log10(1000)3.0
frexpDecompose to x * (2 ^ y)math.frexp(160)0.625 8
ldexpCompute x * (2 ^ y)math.ldexp(0.625,8)160.0
sinSinemath.sin(math.rad(30))0.5
cosCosinemath.cos(math.rad(60))0.5
tanTangentmath.tan(math.rad(45))1.0
asinArcsinemath.deg(math.asin(0.5))30.0
acosArccosinemath.deg(math.acos(0.5))60.0
atanArctangentmath.deg(math.atan(1))45.0