快速实施/在C / C POW()函数的近似++ [英] Fast implementation/approximation of pow() function in C/C++

查看:369
本文介绍了快速实施/在C / C POW()函数的近似++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找由 CMATH 提供的功能更快实现或好近似。

I m looking for a faster implementation or good a approximation of functions provided by cmath.

我需要加快下列功能


  1. POW(X,Y)

  2. EXP(Z * POW(X,Y))

  1. pow(x,y)
  2. exp(z*pow(x,y))

其中, z,其中0 X 为(-1.0,1.0)和是(0.0,5.0)

where z<0. x is from (-1.0,1.0) and y is from (0.0, 5.0)

推荐答案

下面是一些approxmiations:

Here are some approxmiations:

  • Optimized pow Approximation for Java and C / C++. This approximation is very inaccurate, you have to try for yourself if it is good enough.
  • Optimized Exponential Functions for Java. Quite good! I use it for a neural net.

如果对战俘的上述近似不够好,你仍然可以尝试用指数函数来代替它,这取决于你的机器和编译器,这可能会更快:

If the above approximation for pow is not good enough, you can still try to replace it with exponential functions, depending on your machine and compiler this might be faster:


  1. X ^ Y = E ^(Y * LN(X))

  2. 而结果: E ^(Z * X ^ Y)= E ^(Z * E ^(Y * LN(X)))

  1. x^y = e^(y*ln(x))
  2. And the result: e^(z * x^y) = e^(z * e^(y*ln(x)))

另一个技巧是当公式的一些参数不经常改变。因此,如果如X和Y大多是恒定的,你可以precalculate X ^ y和重用这个。

Another trick is when some parameters of the formula do not change often. So if e.g. x and y are mostly constant, you can precalculate x^y and reuse this.

这篇关于快速实施/在C / C POW()函数的近似++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆