快速实施/在C / C POW()函数的近似++ [英] Fast implementation/approximation of pow() function in C/C++
问题描述
我正在寻找由 CMATH
提供的功能更快实现或好近似。
I m looking for a faster implementation or good a approximation of functions provided by cmath
.
我需要加快下列功能
-
POW(X,Y)
-
EXP(Z * POW(X,Y))
pow(x,y)
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:
- 优化战俘逼近用于Java和C / C ++ 。这种近似是非常不准确的,你一定要试试自己是否足够好。
- 优化的指数函数。相当不错!我用它的神经网络。
对Java
- 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:
-
X ^ Y = E ^(Y * LN(X))
- 而结果:
E ^(Z * X ^ Y)= E ^(Z * E ^(Y * LN(X)))
x^y = e^(y*ln(x))
- 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屋!