blob: 58449f9c174ea4ac5e9a2a0c5d1a5ef605f62aa6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// -*- mode: java; -*-
// Newtons approximation to the square root
val _test_sqrt = { flt x ->
flt epsilon = 1e-15;
flt guess = x;
while( 1 ) {
flt next = (x/guess + guess)/2;
if( guess-epsilon <= next & next <= guess+epsilon ) return guess;
//if( guess==next ) return guess;
guess = next;
}
};
flt farg = arg; return _test_sqrt(farg) + _test_sqrt(farg+2.0);
|