summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/spill/Chapter24AllocTest-testNewtonInteger.smp
blob: 572e4ad7ebf987901dfb45e06e5f843ee16bfe10 (plain)
1
2
3
4
5
6
7
8
9
10
11
// 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;
    }
};
int cast_int = arg+2;
return _sqrt(arg) + _sqrt(cast_int);