当前位置:首页技术屋课程5.常用的一些函数
内容广告区块

5.常用的一些函数

5.常用的一些函数

1.基础函数
函数名 函数功能示例
type(v) 用来判断v的类型, 返回字符串”nil”, “number”, “string”, “boolean”, “table”, “function”, “thread”, “userdata”type(1)
tonumber(e [,base]) 把e(必须为数字或者是可以转成数字的字符串)转成10进制数字,base为多少进制(可以为2-36),默认为10tonumber(’10’)10
tostring(e) 把任意类型的e已适当的方式转成字符串,如果e的原表有__tostring函数,则调用并传入e作为参数,把返回值作为结果返回。math.asin(0.5)0.52359877
pcall (f [, arg1, ···]) 在保护模式下调用函数(即发生的错误将不会反射给调用者)
assert (v [, message]) 相当于C的断言,v:当表达式v为nil或false将触发错误,
message:发生错误时返回的信息,默认为”assertion failed!”
print (···) 简单的以tostring方式格式化输出参数的内容

  1. 数学函数
    math.pi 为圆周率常量 = 3.14159265358979323846

函数名 函数功能 示例 示例结果
abs 取绝对值 math.abs(-15) 15
acos 反余弦函数 math.acos(0.5) 1.04719755
asin 反正弦函数 math.asin(0.5) 0.52359877
atan2 x / y的反正切值 math.atan2(90.0, 45.0) 1.10714871
atan 反正切函数 math.atan(0.5) 0.463647609
ceil 不小于x的最大整数 math.ceil(5.8) 6
cosh 双曲线余弦函数 math.cosh(0.5) 1.276259652
cos 余弦函数 math.cos(0.5) 0.87758256
deg 弧度转角度 math.deg(math.pi) 180
exp 计算以e为底x次方值 math.exp(2) 2.718281828
floor 不大于x的最大整数 math.floor(5.6) 5
fmod (mod) 取模运算 math.mod(14, 5) 4
frexp 把双精度数val分解为数字部分(尾数)和以2为底的指数n,即val=x*2n math.frexp(10.0) 0.625 4
ldexp 计算value * 2的n次方 math.ldexp(10.0, 3) 80 = 10 * (2 ^3)
log10 计算以10为基数的对数 math.log10(100) 2
log 计算一个数字的自然对数 math.log(2.71) 0.9969
max 取得参数中最大值 math.max(2.71, 100, -98, 23) 100
min 取得参数中最小值 math.min(2.71, 100, -98, 23) -98
modf 把数分为整数和小数 math.modf(15.98) 15 98
pow 得到x的y次方 math.pow(2, 5) 32
rad 角度转弧度 math.rad(180) 3.141592654
random 获取随机数 math.random(1, 100) 获取1-100的随机数
randomseed 设置随机数种子 math.randomseed(os.time()) 在使用math.random函数之前必须使用此函数设置随机数种子
sinh 双曲线正弦函数 math.sinh(0.5) 0.5210953
sin 正弦函数 math.sin(math.rad(30)) 0.5
sqrt 开平方函数 math.sqrt(16) 4
tanh 双曲线正切函数 math.tanh(0.5) 0.46211715
tan 正切函数 math.tan(0.5) 0.5463024

————————————————
版权声明:本文为CSDN博主「一屁小肥咩」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011271894/article/details/118656465

To get a license to the CA game Internet club, you need to fulfill a https://mystake-casino.co.uk/ of conditions. At the beginning of 2021, GC GB issued more than 3300 permits and controls the work of more than 2400 operators.

To get a license to the CA game Internet club, you need to fulfill a https://mystake-casino.co.uk/ of conditions. At the beginning of 2021, GC GB issued more than 3300 permits and controls the work of more than 2400 operators.

温馨提示:

文章标题:5.常用的一些函数

文章链接:https://www.ggelua.cn/88/

更新时间:2024年02月16日

版权声明

   本站资源采集于互联网,仅作为技术研究使用,不拥有所有权,不承担相关法律责任,请下载后24小时内自行删除。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请 联系我们 一经核实,立即删除。并对发布账号进行永久封禁处理。在为用户提供最好的产品同时,保证优秀的服务质量。


本站仅提供信息存储空间,不拥有所有权,不承担相关法律责任。

给TA打赏
共{{data.count}}人
人已打赏
课程

4.什么是循环

2023-7-13 16:34:38

课程

6.对象和类

2023-7-16 18:10:27

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索