Jump to content
Sign in to follow this  
Gord P

speed of pow() in c++

Recommended Posts

The pow(x, y) function is a bit of a bottleneck for me.  My exponents have to be doubles so I can't trade it out for multiplication routines.  After searching around, I see that this is a common issue in c++ and there is no simple fix.  I'm just curious if others had come across something to help speed things up.  Accuracy is an issue for me, so approximate solutions aren't appropriate.

Share this post


Link to post

I don't use C++ anymore but I assume that like everybody else (Delphi for one) it's using pow(x, y) = exp(y * log(x)) and I doubt that you'll find anything faster than that.

Here's an implementation:

https://github.com/lattera/glibc/blob/master/sysdeps/ieee754/dbl-64/e_pow.c

Looks pretty optimized to me. Of course you'll need a decent compiler to turn it into something that actually takes advantage of the processor features.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×