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.
2.0
x
pow(2.0, x)
Friend for integers 1<<n, but it only works for integers n.
1<<n
n
There is a standard std::exp2(double n)
std::exp2(double n)
Computes 2raised to a given powern
2
It may exp2(x)not be faster than pow(2.0, x)in a specific environment, but more specific than general pow.
exp2(x)
pow
std::ldexp:
std::ldexp
double x = std::ldexp(1.0, k); // 2 to the power of k
, 1<<k , .
1<<k