关于Lua中的地板除是在项目中看到,由于比较少见,于是进行记录一下;Lua中使用//
表示为地板除;它的效果其实和数学库中的math.floor()
向下取整的效果是一样的,意思为:对一个数进行除法运算后向下取整
print(9//2) --> 4
print(math.floor(9/2)) --> 4
并且两个语句执行的速度好像差不多,不过Lua的地板除在一些教程中都不怎么常见,于是去官网中看了一下;
关于//地板除lua官网中是这样介绍的:
Floor division () is a division that rounds the quotient towards minus infinity, that is, the floor of the division of its operands. //
Modulo is defined as the remainder of a division that rounds the quotient towards minus infinity (floor division).
参考链接:Lua官网