From 532b34d34fde93b2841f4c9544c673a0d89434ea Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 5 Apr 2025 15:53:10 -0700 Subject: Fix vs0 bugs Use a BoolNode.NE instead of inverting outputs; the outputs are already matched and cannot be inverted. Use a `swap` not an `invert` when switching sides in a compare. --- chapter21/src/test/java/com/seaofnodes/simple/Chapter20Test.java | 2 +- chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java | 2 +- chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'chapter21/src/test/java') diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter20Test.java index da58b76e..69179043 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter20Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter20Test.java @@ -74,7 +74,7 @@ return sqrt(arg) + sqrt(arg+2); public void testNewtonFloat() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp")) + "flt farg = arg; return test_sqrt(farg) + test_sqrt(farg+2.0);"; - testCPU(src,"x86_64_v2", "SystemV",23,null); + testCPU(src,"x86_64_v2", "SystemV",39,null); testCPU(src,"riscv" , "SystemV",17,null); testCPU(src,"arm" , "SystemV",18,null); } diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java index c3f9193e..5f68d0e3 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -47,7 +47,7 @@ public class Chapter21Test { public void testNewtonFloat() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp")) + "flt farg = arg; return test_sqrt(farg) + test_sqrt(farg+2.0);"; - testCPU(src,"x86_64_v2", "SystemV",23,null); + testCPU(src,"x86_64_v2", "SystemV",39,null); testCPU(src,"riscv" , "SystemV",18,null); testCPU(src,"arm" , "SystemV",19,null); } diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp index 1389e12d..c76e942f 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp @@ -1,12 +1,12 @@ // -*- mode: java; -*- // Newtons approximation to the square root val test_sqrt = { flt x -> - //flt epsilon = 1e-57; + flt epsilon = 1e-57; 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; + if( guess-epsilon <= next & next <= guess+epsilon ) return guess; + //if( guess==next ) return guess; guess = next; } }; -- cgit v1.2.3