math.fmod介绍
math.fmod返回参数x相对于参数y的余数,即math.fmod(x, y) = x - n*y,n是x/y的商并向0方向取整。
math.fmod使用
如下例子:
io.write("math.fmod(1, 2)=", math.fmod(1, 2), "\n")
io.write("math.fmod(2, 3)=", math.fmod(2, 3), "\n")
io.write("math.fmod(3, 1)=", math.fmod(3, 1), "\n")
io.write("math.fmod(3, 1.1)=", math.fmod(3, 1.1), "\n")
io.write("math.fmod(math.huge, math.huge)=", math.fmod(math.huge, math.huge), "\n")
io.write("math.fmod(math.huge, 100)=", math.fmod(math.huge, 100), "\n")
输出如下:
math.fmod(1, 2)=1
math.fmod(2, 3)=2
math.fmod(3, 1)=0
math.fmod(3, 1.1)=0.8
math.fmod(math.huge, math.huge)=-nan
math.fmod(math.huge, 100)=-nan
math.fmod总结
math.fmod用于求余数,接收两个参数x、y,两个参数即可以是整数也可以是浮点数,但y不能为0。