如何计算任意幂/根?
我有一个应用程序需要将数字提高到分数次幂。目标平台是 FPGA,我可以估算它的 FPU 大小,但我需要一种算法来将数字提高到分数幂,只是为了进行可行性研究。我假设浮点是最坏的情况,我希望在实践中我们能够使用捷径,但现在我想表明最坏的情况可以由我们来实现。
我想我应该在这里问一下,看看是否有任何常见的方法可以检查。我知道有软件方法可以做到这一点,我想要一个相当有效的算法来开始。我会担心 FPGA 的实现。
I have a application which needs to raise a number to a fractional power. The target platform is an FPGA and I can get estimates on an FPU size for it, but I need an algorithm for raising a number to a fractional power just for a feasibility study. I'm assuming floating point as a worst case, I expect in practice we will be able to use short cuts, but for now I want to show that worst case can be implemented on our part.
Thought I'd ask here and see if there were any common methods that I could checkout. I know there are software methods of doing this, I want just a reasonably efficient algorithm to start with. I'll worry about the FPGA implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的输入范围是任意的,还是在某个范围内已知的?
无论哪种情况,xm = exp(m log x),因此如果您可以创建函数来计算 exp(x) 和 log(x) 并进行乘法运算,那么您可能已经准备就绪。
您必须弄清楚如何处理 x 的非正值。
(log(x) 提示:如果这是 IEEE-754 浮点,则将如有必要,直到您最终得到某个值 K 的 2k 和 2k+1 之间的数字范围。这使您可以处理 2:1 的范围,其中用多项式近似并不难。那么您只需处理指数和移位数的少量可能性即可
:写出 x = k+b,其中 0 <= b <。 ; 1 且 k 是一个整数。那么 exp(x) = exp(k)*exp(b); b 的范围有限,k 的离散可能性数量有限。)
(提示 #2:这些数字可能会更好 )对于 xm = g(mf(x)),其中 f(x) = log2x 且 g(x) = 2x。 )
Is your range of inputs arbitrary, or known within a certain range?
in either case, xm = exp(m log x), so if you can create functions to evaluate exp(x) and log(x) and have a multiply, you're probably all set.
You'll have to figure out how you want to handle nonpositive values of x.
(hint for log(x): if this is IEEE-754 floating point, shift the significand if necessary until you end up with a range of numbers between 2k and 2k+1 for some value K. This lets you deal with a 2:1 range which isn't too hard to approximate with polynomials. Then you just have a small number of possibilities to handle for the exponent and the shift number.
Corresponding hint for exp(x): write x = k+b where 0 <= b < 1 and k is an integer. Then exp(x) = exp(k)*exp(b); b has limited range and k has a limited number of discrete possibilities.)
(hint #2: the numbers probably work out better for xm = g(m f(x)) where f(x) = log2x and g(x) = 2x.)
正如 Jason S 所说,这是使用恒等式 xm = exp(m log x) 完成的。但在实践中,您将不得不处理截断错误。
我认为通常这样做的方式是
As Jason S said, this is done using the identity xm = exp(m log x). In practice though, you will have to deal with truncation errors.
I think that the way this is usually done is