相关疑难解决方法(0)

这是获得数字绝对值的最快方法

哪个是实现返回数字绝对值的操作的最快方法?

x=root(x²)
Run Code Online (Sandbox Code Playgroud)

要么

if !isPositive(x):
    x=x*(-1)
Run Code Online (Sandbox Code Playgroud)

实际上这个问题可以翻译为,有多快if(为什么请).

我的大学程序教授总是告诉我要避免使用ifs,因为它们非常慢,但我总是忘记问多慢和为什么.这里有人知道吗?

theory algorithm performance absolute-value

40
推荐指数
6
解决办法
3万
查看次数

标签 统计

absolute-value ×1

algorithm ×1

performance ×1

theory ×1