你好组, 是否有一些快速电源功能的参考实现? 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
推荐答案Chris Forone: Chris Forone: 你好组, 是否有一些快速电源功能的参考实现? 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
Tomásóhéilidhe写道: Tomás ó héilidhe wrote: 很可能是计算该平台权力的最快方法。 Very probably the fastest method of calculating powers for that platform.
不一定在所有情况下。 例如在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.
标准库有没有意义函数 只处理整数指数? unsigned pow_int(unsigned const x,unsigned exp) { unsigned retval = 1; while(; exp; --exp)retval * = x; 返回retval ; } - $ b $bTomásóhéilidhe Would it not make sense for the standard library to have a pow function that deals only with integer exponents? unsigned pow_int(unsigned const x,unsigned exp) { unsigned retval = 1; while ( ; exp; --exp) retval *= x; return retval; } -- Tomás ó héilidhe
更多推荐
快速功能
发布评论