# CELT's numerical approximation of 2^x

0

I cam cross a fast good approximation routine from celt as (https://chromium.googlesource.com/chromium/deps/opus/+/1.0.x/celt/mathops.h), you can see code as below:

``````/** Base-2 exponential approximation (2^x). */
static inline float celt_exp2(float x)
{
int integer;
float frac;
union {
float f;
opus_uint32 i;
} res;
integer = floor(x);
if (integer < -50)
return 0;
frac = x-integer;
/* K0 = 1, K1 = log(2), K2 = 3-4*log(2), K3 = 3*log(2) - 2 */
res.f = 0.99992522f + frac * (0.69583354f
+ frac * (0.22606716f + 0.078024523f*frac));
res.i = (res.i + (integer<<23)) & 0x7fffffff;
return res.f;
}
``````

It's fast and approximate well, so I want to figure out how it does behind. It seems that it uses polynomial approximation to approximate, but when I use Taylor expansion and Remez algorithm to fit it, both don't work.

2^x = 1 + ln(2)x + (3-4log(2))x^2 + (3log(2) - 2)x^3

Do somebody know which polynomial approximation it is using, it suffers to find a solution work but don't know why.

Thx very much.

approximation
polynomial-approximations