要避免任何数与 0 相除或溢出,将所有除法转换为乘法并检查运算符号(Y2=Y1 的水平线不会计入算法)
To avoid any division by zero or overflow, transform all division into multiplication and check for the sign (horizontal lines with Y2=Y1 do not count in the algorithm)
如果我们能够确定其中的一个操作数为unsigned,那么使用无符号除法将会更好,因为它要比有符号除法快得多。
It will be better to use unsigned division by ensuring that one of the operands is unsigned, as this is faster than signed division.
有符号的除法要耗费更多的时间,因为除法是使最终结果趋向于零的,而移位则是趋向于负无穷。
The signed division will take more time to execute because it rounds towards zero, while a shift rounds towards minus infinity.
应用推荐