blob: 8912dcd929dc22d9c2a04a9f4f6e2e0c6843a142 (
plain)
1
2
3
4
5
6
7
8
9
10
|
// Newtons approximation to the square root
val _sqrt = { int x ->
int guess = x;
while( 1 ) {
int next = (x/guess + guess)/2;
if( next == guess ) return guess;
guess = next;
}
};
return _sqrt(arg) + _sqrt(arg+2);
|