Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast floating-point power of 2 on x86_64

Is there a fast way to take 2.0 to some floating-point degree x? I mean something faster than pow(2.0, x) and preferrably what vectorizes well with AVX2.

The counterpart for integers is 1<<n, but it works for integer n only.

like image 223
Serge Rogatch Avatar asked Aug 23 '17 10:08

Serge Rogatch


1 Answers

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

Computes 2 raised to the given power n

It is possible that exp2(x) would not be faster than pow(2.0, x) in a particular environment but it's more specific than general pow.

like image 180
DAle Avatar answered Oct 19 '22 20:10

DAle