View Single Post
Old 07-24-2009, 06:08 AM   #12
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default fast pow() from identity

using the above approximation of exp() and the identity:
Code:
2^x=exp(x*log(2));
it is possible to get a fixed base approximation of b^x:
Code:
@init
//base 2
b=log(2);
@sample
//example with 4 point polynomial:
x*=b;
y=x;
y*=0.189;
y+=0.612;
y*=x;
y+=0.995;
y*=x;
y+=0.975;

//x=1 -> y=2.02166035;
//x=2 -> y=4.03404514;
stable within x range [-2, 2,5]

[img]http://img233.**************/img233/9909/powlagrange.gif[/img]

performance test (100 executions per sample):
4point approximation (2^x) - 33%
inline 2^x - 75%

---

lubomir
liteon is offline   Reply With Quote