要避免任何数与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.
这两个除法都会避免调用除法函数,另外,无符号的除法要比有符号的除法使用更少的指令。
Both divisions will avoid calling the division function and the unsigned division will take fewer instructions than the signed division.
这两个除法都会避免调用除法函数,另外,无符号的除法要比有符号的除法使用更少的指令。
Both divisions will avoid calling the division function and the unsigned division will take fewer instructions than the signed division.
应用推荐