问题描述
你好组,
是否有一些快速电源功能的参考实现?
fast是< cmath>中的幂函数?
谢谢&手,克里斯
hello group,
is there some reference implementation of a fast power function? how
fast is the power function in <cmath>?
thanks & hand, chris
推荐答案
非常可能是计算该平台功率的最快方法。
-
$ b $bTomás óhéilidhe
Very probably the fastest method of calculating powers for that platform.
--
Tomás ó héilidhe
不一定在所有情况下。
例如在intel架构中,pow()相当慢,因为
387中没有这样的FPU操作码。我们可能正在谈论很多
,如果不是甚至在Pentium上也不会超过一千个时钟周期。
虽然编译器可能会尝试优化pow()调用,如果他们可以,
他们通常不能。
在某些情况下它可能更快开放一个计算比
调用pow()。例如,在许多情况下,执行
pow(x,1.5)可能会更慢。而不是x * sqrt(x) (许多编译器都无法优化前者到后者的
。)
但当然这与架构和编译器的关系比
更多
到C ++,因此稍微偏离主题。
Not necessarily in all cases.
For example in intel architectures pow() is rather slow because
there''s no such FPU opcode in 387. We are probably talking about many
hundreds, if not even over a thousand clock cycles even on a Pentium.
While compilers may try to optimize the pow() call away if they can,
they often can''t.
In some cases it may be faster to "open up" a calculation than
calling pow(). For example, in many cases it may be slower to perform a
"pow(x, 1.5)" than a "x*sqrt(x)" (many compilers are unable to optimize
the former into the latter).
But of course this is more related to architectures and compilers than
to C++, and thus slightly off-topic.
这篇关于快速功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!