diff options
| author | Cliff Click <cliffc@acm.org> | 2025-04-20 10:46:50 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-04-20 10:46:50 -0700 |
| commit | 0f3ece57429baf2014fd08a4fd167c6ad7b1315b (patch) | |
| tree | 0e2bba197ed2be45264c35917f6bd8cea3878a9b | |
| parent | d761c267362e618e9e01de5b1fc0a405f5b466dc (diff) | |
| download | Simple-0f3ece57429baf2014fd08a4fd167c6ad7b1315b.tar.gz Simple-0f3ece57429baf2014fd08a4fd167c6ad7b1315b.zip | |
Correct test case ULP
3 files changed, 14 insertions, 16 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 50cb7604..2a5082a0 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -75,16 +75,16 @@ public class Chapter21Test { @Test public void testNewtonExport() throws IOException { String result = """ -0 0.000000 -1 1.000000 -2 1.414214 -3 1.732051 -4 2.000000 -5 2.236068 -6 2.449490 -7 2.645751 -8 2.828427 -9 3.000000 +0 0.000000 (0) +1 1.000000 (0) +2 1.414214 (2.22045e-16) +3 1.732051 (0) +4 2.000000 (0) +5 2.236068 (0) +6 2.449490 (0) +7 2.645751 (0) +8 2.828427 (4.44089e-16) +9 3.000000 (0) """; TestC.run("newtonFloat",result,34); diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.c b/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.c index 91ff97ec..7e7e796d 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.c +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.c @@ -2,16 +2,14 @@ #include <math.h> #include <stdlib.h> -__attribute__ ((CALL_CONV)) extern double test_sqrt(double); int main( int argc, char** argv ) { - double epsilon = 1e-50; for( int i=0; i<10; i++ ) { double d = test_sqrt((double)i), expect = sqrt((double)i); - double delta = abs(d-expect); - printf("%d %f (%f)\n",i,d,delta); - if( delta > 1e-50 ) + double delta = fabs(d-expect); + printf("%d %f (%g)\n",i,d,delta); + if( delta > 1e-15 ) return 1; } return 0; 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 c76e942f..be2dffec 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp @@ -1,7 +1,7 @@ // -*- mode: java; -*- // Newtons approximation to the square root val test_sqrt = { flt x -> - flt epsilon = 1e-57; + flt epsilon = 1e-15; flt guess = x; while( 1 ) { flt next = (x/guess + guess)/2; |
