Fast floating point power 2 on x86_64

Is there a quick way to take 2.0some floating point x? I mean something faster than pow(2.0, x), and it is desirable that is well positioned with AVX2.

Friend for integers 1<<n, but it only works for integers n.

+6
source share
2 answers

There is a standard std::exp2(double n)

Computes 2raised to a given powern

It may exp2(x)not be faster than pow(2.0, x)in a specific environment, but more specific than general pow.

+9

std::ldexp:

 double x = std::ldexp(1.0, k); // 2 to the power of k

, 1<<k , .

+1

All Articles