最近发现lua取模的两种方法,结果会不同,在此记录一下。
方法一:a%b
计算公式
其中,
> 2%3
2
> -2%3
1
> 2%-3
-1
> 2%(-3)
-1
> -2%(-3)
-2
> (-2)%(-3)
-2
方法二:math.fmod( a,b)
计算公式
其中,
> math.fmod(2,3)
2
> math.fmod(-2,3)
-2
> math.fmod(-2,-3)
-2
> math.fmod(2,-3)
2