본문으로 건너뛰기

math 라이브러리 활용

함수 이름설명예제결과
pi원주율math.pi3.1415926535898
abs절댓값math.abs(-2012)2012
ceil올림math.ceil(9.1)10
floor내림math.floor(9.9)9
max인수의 최댓값math.max(2,4,6,8)8
min인수의 최솟값math.min(2,4,6,8)2
x^yx의 y제곱 계산(Lua 5.3부터 math.pow가 제거되어 ^ 연산자 사용)2^1665536.0
sqrt제곱근math.sqrt(65536)256.0
modf정수 부분과 소수 부분 가져오기math.modf(20.12)20 0.12
randomseed난수 시드 설정math.randomseed(os.time())
random난수 가져오기math.random(5,90)5~90
rad각도를 라디안으로 변환math.rad(180)3.1415926535898
deg라디안을 각도로 변환math.deg(math.pi)180.0
expe의 x제곱math.exp(4)54.598150033144
logx의 자연로그 계산math.log(54.598150033144)4.0
log (밑 지정)지정한 밑의 로그 계산(Lua 5.3부터 math.log10이 제거되어 math.log(x, 10) 사용)math.log(1000, 10)3.0
frexp인수를 x * (2 ^ y) 형식으로 분해math.frexp(160)0.625 8
ldexpx * (2 ^ y) 계산math.ldexp(0.625,8)160.0
sin사인math.sin(math.rad(30))0.5
cos코사인math.cos(math.rad(60))0.5
tan탄젠트math.tan(math.rad(45))1.0
asin아크사인math.deg(math.asin(0.5))30.0
acos아크코사인math.deg(math.acos(0.5))60.0
atan아크탄젠트math.deg(math.atan(1))45.0