All Comments
TopTalkedBooks posted at August 20, 2017

You could start converting this java snippet to C the author states he has converted it from C based on the book numerical recipies which you find online! here

TopTalkedBooks posted at August 20, 2017
TopTalkedBooks posted at August 20, 2017

I checked this post, but it worked only for whole numbers (1,2,3... not 0.1, 0.3...)

Recursive power function: Why does this work if there's no initial return value?


I got this from here : Algorithm for pow(float, float)

function power(x,n) {
    if(n === 0) return 1;
    if(n === -1) return 1/x;
    if(n === 1) return x;
    return Math.exp(n*Math.log(x))


I added some basic checks (n===0)... To fasten things up in case.

Flexo sums it up :

The general algorithm tends to be computing the float power as the combination of the integer power and the remaining root. The integer power is fairly straightforward, the root can be computed using either Newton - Raphson method or Taylor series. IIRC numerical recipes in C has some text on this. There are other (potentially better) methods for doing this too, but this would make a reasonable starting point for what is a surprisingly complex problem to implement. Note also that some implementations use lookup tables and a number of tricks to reduce the computation required.

Top Books
We collected top books from hacker news, stack overflow, Reddit, which are recommended by amazing people.