Perl: the Markov chain saw  
PerlMonks 
Comment on 
( #3333=superdoc: print w/ replies, xml )  Need Help?? 
Another solution based on the fact that a floating point number is actually a sum of powers of 2.
For 0 <= y <= 0, it holds that y = b_{0}*2^{0} + b_{1}*2^{1} + b_{2}*2^{2} + b_{3}*2^{3} + ... And so, x^{y} = x^{b0*20 + b1*21 + b2*22 + b3*23 + ...} = x^{b0*20} * x^{b1*21} * x^{b2*22} * x^{b3*23} * ... = Π_{i, bi≠0} x^{2i} Which in Perl becomes...
sqrt is also an expensive operation. If you have to calculate x^{y} for different values of y while x stays constant, you may be able to speed up the process creating a table with the values of x^{2i}. Alternatively, you can write a function to calculate e^{x} (using a table with the values of e^{2i}), and then calculate x^{y} as e^{log(x)*y}. update: there are also several implementations of exp(x) freely available, for instance, the one in OpenBSD is here. In reply to Re: [OT] Function to do x**y for y<1 w/o ** operator.
by salva

