summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-07-30 07:29:13 -0700
committerDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2024-08-05 23:28:33 +0100
commitac1182230a1714e98abf15665cccbcb2bc69c157 (patch)
tree9d9b378fdfd585cf51a4bd37105f628e9efa464d
parent2b35a316dbafd1aa27b2b49aeb868e1f357362a9 (diff)
downloadSimple-ac1182230a1714e98abf15665cccbcb2bc69c157.tar.gz
Simple-ac1182230a1714e98abf15665cccbcb2bc69c157.zip
Update Ch12 readme
-rw-r--r--chapter12/README.md46
1 files changed, 45 insertions, 1 deletions
diff --git a/chapter12/README.md b/chapter12/README.md
index 19c3f850..e381f1dc 100644
--- a/chapter12/README.md
+++ b/chapter12/README.md
@@ -1,3 +1,47 @@
-# Chapter 12
+# Chapter 12: Floats, Arrays, Refs
+
+## Floats
+
+In this chapter we add a series of new types and some modest syntax.
+
+Floating point values start with the `flt` type and compute IEEE754 64-bit arithmetic.
+Integer expressions auto-widen to floats when involved in a float expression.
+
+```java
+flt f = 0.5;
+int x = 2;
+f = f+x; // Auto-widen x to 2.0, result is 2.5
+f = f+true; // Since bools are just synonyms for integers 0,1 they auto-widen also
+```
+
+
+Here is Newton's method to a square root:
+```java
+flt guess = arg; // Initial guess is just argument
+while( true ) {
+ // Next guess from Newton's method
+ flt next = (arg/guess + guess)/2;
+ // Break if hit fixed point
+ if( next == guess ) break;
+ guess = next;
+}
+return guess;
+```
+When run with argument 2.0, produces 1.414213562373095.
+
+Floating point operations have their own Nodes:
+
+| Node | Op |
+|------------------------|----------------------|
+| AddF, SubF, MulF, DivF | Basic binary FP ops |
+| MinusF | Unary negate |
+| EQF, LTF, LEF | FP compare operators |
+
+And their own section in the Type lattice:
+
+Within the Type Lattice, we now add the following domain:
+
+* Float type - Float values. The same shape as the Integer values, but floats
+ with a TOP, BOT and constants