local math = require("math") --引入标准库
-- abs: function(x), (取x绝对值)
local x = -1
print("普通值 = ",x)
print("绝对值 = ", math.abs(x))
-- ceil: function(x number),(向上取整)
print("向上取整 = ",math.ceil(1.23))
-- floor: function(x number),(向下取整)
print("向下取整", math.floor(1.23))
--三角函数
-- pi: number, (返回pi的值)
print("pi的值=", math.pi)
-- deg: function(x number),(返回角度,参数是弧度)
print("角度=", math.deg(1))
--弧度和角度的换算方式:rad=degree*pi/180。1rad约等于57.3度
-- rad: function(x number),(返回的是弧度,参数是角度)
print("弧度=", math.rad(45))
-- sin: function(x number),(返回的是值,参数是弧度,用math.rad)
print("sin = ", math.sin(math.rad(30)))
-- cos: function(x number), (返回的是值,参数是弧度,用math.rad)
print("cos = ", math.cos(math.rad(30)))
-- tan: function(x number),(返回的是值,参数是弧度,用math.rad)
print("tan = ",math.tan(math.rad(30)))
-- acos: function(x number),(反余弦)
print("反余弦 = " ,math.acos(math.cos(math.rad(30))))
-- asin: function(x number),(反正弦)
print("反正弦 = ", math.asin(math.sin(math.rad(30))))
-- atan: function(x number),(反正切)
print("反正切 = ", math.atan(90,45))
-- exp: function(x number),(计算以e为底x次方值)
print("exp = ",math.exp(10))
-- fmod: function(x number, y number),(求余数)
print("fmod = ",math.fmod(10,3))
-- frexp: function(x:number),(把双精度数val分解为数字部分(尾数)和以2为底的指数n,即val=x*2n)
print("frexp = ",math.frexp(12))
-- huge: number,(它被赋予了一个浮点值,这个值相当于数学上的正无穷大。它和任何其他数值相加减得它本身。它作为分母,则值为0 )
print("huge = ", math.huge)
-- ldexp: function(m, e),(m * (2 ^ e))
print("ldexp = ", math.ldexp(2,1))
-- log: function,(返回以2为底10的对数)
print("log = ", math.log( 10,2))
-- log10: function,(返回以10为底对数)
print("log10 = ", math.log10(100))
-- max: function,(返回可变参数的最大值)
print("max",math.max(1,2,3,4))
-- maxinteger: integer,(最大整型值)
print("maxinteger = ", math.maxinteger)
-- min: function,(返回可变参数的最小值)
print("min",math.min(1,2,3,4))
-- mininteger: integer,(返回整型最小值)
print("mininteger = ", math.mininteger)
-- modf: function,(把数分为整数和小数)
print("modf = ", math.modf(12.88))
-- pow: function,(得到x的y次方)
print(math.pow(2, 8))
-- sqrt: function(x number),(开平方函数)
print("sqrt = ", math.sqrt(16))
-- tointeger: function(x number), (转整型)
print("tointeger = ", math.tointeger(12))
-- type: function(x any),(判断一个数是整型还是浮点型)
print("type = ", math.type(101))
-- ult: function(x number, y number),(函数把x和y作为无符号整数比较,如果x小于y,则返回true。否则返回false)
print("ult = ", math.ult(0x7fffffffffffffff,0x8000000000000000))
--随机数
-- random: function(any),(返回范围类随机数)
print("随机数 = ", math.random(1,10)) --每次都一样,具体https://blog.csdn.net/goodai007/article/details/59579515
-- randomseed: function,(设置随机种子数,不设置的话,每次返回的随机数是一样的)
math.randomseed(os.time())
print("增加种子随机数 = ", math.random(1,100))