哪个是实现返回数字绝对值的操作的最快方法?
x=root(x²)
要么
if !isPositive(x): x=x*(-1)
实际上这个问题可以翻译为,有多快if(为什么请).
if
我的大学程序教授总是告诉我要避免使用ifs,因为它们非常慢,但我总是忘记问多慢和为什么.这里有人知道吗?
theory algorithm performance absolute-value
absolute-value ×1
algorithm ×1
performance ×1
theory ×1