快速功能

编程入门 行业动态 更新时间:2024-10-28 11:19:33
本文介绍了快速功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好组, 是否有一些快速电源功能的参考实现? 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

更多推荐

快速功能

本文发布于:2023-11-26 04:36:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632648.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快速   功能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!