Main Archive Specials Wiki | FAQ Links Submit Forum

Piecewise quadratic approximate exponential function

Type : Approximation of base-2 exponential function
References : Posted by Johannes M.-R.

Notes :
The code assumes round-to-zero mode, and ieee 754 float.
To achieve other bases, multiply the input by the logarithmus dualis of the base.

Code :
inline float fpow2(const float y)
float f;
int i;
} c;

int integer = (int)y;
if(y < 0)
integer = integer-1;

float frac = y - (float)integer;

c.i = (integer+127) << 23;
c.f *= 0.33977f*frac*frac + (1.0f-0.33977f)*frac + 1.0f;

return c.f;


There are no comments on this item

Add your own comment
Comments are displayed in fixed width, no HTML code allowed!


Are you human?

Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion