---[[ Modules ]]---
-- Include code other files
-- 可以加載需要使用的庫

---[[ Method 1 ]]---
-- require("myMath")
-- myMath.function(a,b)

---[[ Method 2 ]]---
-- local math = require("myMath")
-- math.function(a,b)

---[[ Method 3 ]]---
-- require("myMath")
-- local mathFunction = myMath.function 
-- mathFunction(a,b)




---[[ Math ]]---
-- The math class has a number of functions for dealing with numbers.

--abs (absolute value)
print("----Absolute----")
local x = -10
print(math.abs(x)) 
local a = 99
print(math.abs(a)) 

--sqrt (Square root of a number)
print("----Square root----")
print(math.sqrt(100)) 




--ceil (round up decimal value) 無條件進位
local x = 1.333
print(math.ceil(x)) --result: 2

--floor (round down decimal value) 無條件捨去
local x = 1.2
print(math.floor(x)) --result: 1


print("----Pi----")
--pi (constant value of pi)
print("Pi is " .. math.pi) --3.1415926535898

print("----Convert value to degrees----")
--deg (Convert value from radians to degrees)
print(math.deg(math.pi)) -- result: 180
print(math.deg(math.pi/2)) -- result: 180

print("----Convert value to radians----")
--rad (Convert value from degrees to radians) #弧度
print(math.rad(180)) --result: 3.1415926535898



print("----Random number----")
--random (random number generation) random value between 0 tand 1
print(math.random())

--random integer value from 1 to 100 (both inclusive)
print(math.random(100)) 

--random integer value from 20 to 100 (both inclusive)
print(math.random(20, 100)) 



Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: