I m looking for a faster implementation or good a approximation of functions provided by cmath
.
I need to speed up the following functions
pow(x,y)
exp(z*pow(x,y))
where z<0
. x
is from (-1.0,1.0) and y
is from (0.0, 5.0)
Here are some approxmiations:
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)))
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.
What are the possible values of x and y? If they are within reasonable bounds, building some lookup tables could help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With