相关疑难解决方法(0)

浮点除法与浮点乘法

通过编码是否有任何(非微优化)性能增益

float f1 = 200f / 2
Run Code Online (Sandbox Code Playgroud)

在比较中

float f2 = 200f * 0.5
Run Code Online (Sandbox Code Playgroud)

几年前我的一位教授告诉我,浮点除法比浮点乘法慢,但没有详细说明原因.

这句话适用于现代PC架构吗?

UPDATE1

关于评论,请同时考虑这个案例:

float f1;
float f2 = 2
float f3 = 3;
for( i =0 ; i < 1e8; i++)
{
  f1 = (i * f2 + i / f3) * 0.5; //or divide by 2.0f, respectively
}
Run Code Online (Sandbox Code Playgroud)

更新2 从评论中引用:

[我想]知道什么是算法/架构要求导致>除法在硬件上比复制要复杂得多

c++ floating-point micro-optimization

67
推荐指数
5
解决办法
5万
查看次数

从硬件架构的角度来看,为什么非规范化浮点数比其他浮点数慢得多?

与法线相比,已知非正规性表现不佳,大约100倍左右.这经常导致意外的软件问题.

我很好奇,从CPU架构角度来看,为什么非正规数必须是多慢?缺乏表现是否是他们不幸的表现所固有的?或者CPU架构师可能会忽略它们以减少硬件成本(错误的)假设非正规无关紧要?

在前一种情况下,如果非正规本质上是硬件不友好的,那么是否已知非IEEE-754浮点表示在零附近也是无间隙的,但是对于硬件实现更方便?

floating-point cpu-architecture

15
推荐指数
1
解决办法
911
查看次数

How does numpy compute an exponential?

After reading this question, I'm wondering what happens under the hood when np.exp is called: what is the mathematical/numerical routine used to derive the values in the returned array? For example, I think that to compute np.sqrt(x), a solution in y to y ** 2 - x = 0 is found using Newton's method.

(np.exp 的文档字符串没有说​​明这是如何完成的)

python math numpy

2
推荐指数
1
解决办法
578
查看次数