This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.

Monday, April 13, 2009

square root

When I have some time, I will have a look to this algorithm to calculate the square root of a number:
    int sqrt(int num) {
int op = num;
int res = 0;
int one = 1 << 14; // The second-to-top bit is set: 1L<<30 for long


// "one" starts at the highest power of four <= the argument.
while (one > op)
one >>= 2;

while (one != 0) {

if (op >= res + one) {
op -= res + one;
res += one << 1;
}

res >>= 1;
one >>= 2;
}
return res;
}

(from Wikipedia)

About Me

My photo
Hamburg, Hamburg, Germany
Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.