summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/spill/Chapter21AllocTest-testNewtonFloat.smp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/spill/Chapter21AllocTest-testNewtonFloat.smp')
-rw-r--r--src/test/java/com/seaofnodes/simple/spill/Chapter21AllocTest-testNewtonFloat.smp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/test/java/com/seaofnodes/simple/spill/Chapter21AllocTest-testNewtonFloat.smp b/src/test/java/com/seaofnodes/simple/spill/Chapter21AllocTest-testNewtonFloat.smp
new file mode 100644
index 00000000..58449f9c
--- /dev/null
+++ b/src/test/java/com/seaofnodes/simple/spill/Chapter21AllocTest-testNewtonFloat.smp
@@ -0,0 +1,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);