Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fast positive integer power function

Name: Anonymous 2012-04-15 6:00

I'm trying to figure out how to compute an integer power of a double efficiently with as little overhead as possible (trying to avoid loops and recursion to minimize the amount of calls and jumps). Calculation speed is the priority.
So far I got this trivial piece of code:

double f(double a,char b){
if(b==2)return a*a;
if(b==3)return a*a*a;
if(b==4)return a*a*a*a;
if(b==5)return a*a*a*a*a;
if(b==6)return a*a*a*a*a*a;
if(b==7)return a*a*a*a*a*a*a;
if(b==8)return a*a*a*a*a*a*a*a;
if(b==9)return a*a*a*a*a*a*a*a*a;
        return a*a*a*a*a*a*a*a*a*a;
}


...which of course assumes the exponent is at most 10. The code can easily be expanded if higher exponents are needed.
I'm thinking this is probably optimal, but I know you /prog/riders have some magic tricks up your sleeve, so hit me with them.

Name: Anonymous 2012-04-16 5:00

>>58
I care. I think it would be fun to overload every seeples operator to do something interesting for numerical stuff.
I do C, not Sepples.
But what's a superposition in this context?
I don't know yet, but I have a feeling I will need it when dealing with infinities, superfunctions, and you know, the unknown. I am faware that math is inherently flawed (according to Gödel) so I will constantly be correcting errors, but never quite get everything right. Then I will implement automatic error correction algorithms, algorithms that correct those algorithms, and so on.
I am so autistic of my nature that I enjoy every second of doing all that shit with no goal, meaning or purpose. As long as it doesn't require conscious effort, it is work that I will do for free. I define conscious effort to be any effort required to hinder oneself. Note that I consider self-destruction and self-domination to be two entirely distinct concepts.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List