summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/spill/Chapter20Test-testNewtonFloat.smp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/spill/Chapter20Test-testNewtonFloat.smp')
-rw-r--r--src/test/java/com/seaofnodes/simple/spill/Chapter20Test-testNewtonFloat.smp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/test/java/com/seaofnodes/simple/spill/Chapter20Test-testNewtonFloat.smp b/src/test/java/com/seaofnodes/simple/spill/Chapter20Test-testNewtonFloat.smp
new file mode 100644
index 00000000..fd76478f
--- /dev/null
+++ b/src/test/java/com/seaofnodes/simple/spill/Chapter20Test-testNewtonFloat.smp
@@ -0,0 +1,11 @@
+// Newtons approximation to the square root
+val _sqrt = { flt x ->
+ flt guess = x;
+ while( 1 ) {
+ flt next = (x/guess + guess)/2;
+ if( next == guess ) return guess;
+ guess = next;
+ }
+};
+flt farg = arg;
+return _sqrt(farg) + _sqrt(farg+2.0);