summaryrefslogtreecommitdiff
path: root/chapter18/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-10-07 12:37:06 -0700
committerCliff Click <cliffc@acm.org>2026-10-07 12:37:06 -0700
commit514b3147bf08817d17aacc492be255621209ec8b (patch)
treed0bc5ba23705d7dae5f0dee3cab15c9beab70917 /chapter18/src/test/java/com/seaofnodes
parent5f51534493763d4aab2f2fc34767de953a08e6a3 (diff)
downloadSimple-514b3147bf08817d17aacc492be255621209ec8b.tar.gz
Simple-514b3147bf08817d17aacc492be255621209ec8b.zip
RoundF32 actually rounds
Diffstat (limited to 'chapter18/src/test/java/com/seaofnodes')
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
index c4d5b9ac..0758fbf5 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
@@ -9,6 +9,33 @@ import static org.junit.Assert.fail;
import org.junit.Ignore;
public class Chapter18Test {
+ @Test public void testFloatArrays() {
+ for( String type : new String[]{"flt","f64","f32"} ) {
+ CodeGen zero = new CodeGen("var a = new "+type+"[arg]; return a[arg-1];")
+ .parse().opto().typeCheck();
+ assertEquals("0.0",Eval2.eval(zero,3));
+ // Eval2 does not execute RoundF32 yet; check nonconstant narrowing here.
+ new CodeGen(type+" x = arg; var a = new "+type+"[arg]; a[0] = x; return a[0];")
+ .parse().opto().typeCheck();
+ }
+ for( String type : new String[]{"flt","f64"} ) {
+ CodeGen loop = new CodeGen("var a = new "+type+"[arg]; "+
+ "for(int i=0; i<arg; i++) a[i] += i+0.25; return a[0]+a[arg-1];")
+ .parse().opto().typeCheck();
+ assertEquals("0.5",Eval2.eval(loop,1));
+ assertEquals("3.5",Eval2.eval(loop,4));
+
+ CodeGen rounded = new CodeGen("var a = new "+type+"[arg]; "+
+ "for(int i=0; i<arg; i++) a[i] = 16777216.0+i; return a[arg-1];")
+ .parse().opto().typeCheck();
+ assertEquals("1.6777217E7",Eval2.eval(rounded,2));
+ }
+ CodeGen rounded = new CodeGen("var a = new f32[arg]; "+
+ "for(int i=0; i<arg; i++) a[i] = 16777217.0; return a[arg-1];")
+ .parse().opto().typeCheck();
+ assertEquals("1.6777216E7",Eval2.eval(rounded,2));
+ }
+
@Test public void testNeverExitLoopDepth() {
String[] sources = {
"if(arg) while(1) {} return 7;",