[MLton-commit] r7295

Wesley Terpstra wesley at mlton.org
Tue Oct 20 07:50:24 PDT 2009


Test the sizes of reals


----------------------------------------------------------------------

A   mlton/trunk/regression/real-basic.ok
A   mlton/trunk/regression/real-basic.sml
A   mlton/trunk/regression/real-basic.x86-darwin.ok
A   mlton/trunk/regression/real-basic.x86-freebsd.ok
A   mlton/trunk/regression/real-basic.x86-linux.ok

----------------------------------------------------------------------

Added: mlton/trunk/regression/real-basic.ok
===================================================================
--- mlton/trunk/regression/real-basic.ok	2009-10-20 14:11:16 UTC (rev 7294)
+++ mlton/trunk/regression/real-basic.ok	2009-10-20 14:50:23 UTC (rev 7295)
@@ -0,0 +1,32 @@
+Real32
+  Reported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    yes
+  Actual
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    yes
+  Exported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    yes
+Real64
+  Reported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    yes
+  Actual
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    yes
+  Exported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    yes

Added: mlton/trunk/regression/real-basic.sml
===================================================================
--- mlton/trunk/regression/real-basic.sml	2009-10-20 14:11:16 UTC (rev 7294)
+++ mlton/trunk/regression/real-basic.sml	2009-10-20 14:50:23 UTC (rev 7295)
@@ -0,0 +1,61 @@
+functor Basic(structure Real : REAL
+              structure Pack : PACK_REAL
+              where type real = Real.real) =
+   struct
+      open Real
+      val () = print "  Reported\n"
+      val () = print ("    precision:    " ^ Int.toString precision ^ "\n")
+      val {man=_, exp} = toManExp maxFinite
+      val () = print ("    max exponent: " ^ Int.toString exp ^ "\n")
+      val {man=_, exp} = toManExp minPos
+      val () = print ("    min exponent: " ^ Int.toString exp ^ "\n")
+      val () = print ("    subnormal:    yes\n")
+      
+      (* Now let's compute the actual mantissa *)
+      val zero = fromInt 0
+      val one = fromInt 1
+      val two = fromInt 2
+      
+      fun precision eq x =
+         if eq (x+one, x) then 0 else
+         Int.+ (1, precision eq (x+x))
+      fun maxExp inf x =
+         if inf (x+x) then 1 else
+         Int.+ (1, maxExp inf (x+x))
+      fun minExp zero x =
+         if zero (x / two) then 1 else
+         Int.- (minExp zero (x / two), 1)
+      fun deNorm zero =
+         if zero (minPos * (one + one / two) - minPos) then "no" else "yes"
+      
+      val xprecision = precision == one
+      val xmaxExp = maxExp (not o isFinite) one
+      val xminExp = minExp (fn z => == (z, zero)) one
+      val xdeNorm = deNorm (fn z => == (z, zero))
+      
+      val () = print "  Actual\n"
+      val () = print ("    precision:    " ^ Int.toString xprecision ^ "\n")
+      val () = print ("    max exponent: " ^ Int.toString xmaxExp ^ "\n")
+      val () = print ("    min exponent: " ^ Int.toString xminExp ^ "\n")
+      val () = print ("    subnormal:    " ^ xdeNorm ^ "\n")
+      
+      val a = Word8Array.array (Pack.bytesPerElem, 0w0)
+      fun id x = (Pack.update (a, 0, x); Pack.subArr (a, 0))
+      val xprecision = precision (fn (x, y) => == (id x, id y)) one
+      val xmaxExp = maxExp (not o isFinite o id) one
+      val xminExp = minExp (fn z => == (id z, zero)) one
+      val xdeNorm = deNorm (fn z => == (id z, zero))
+      
+      val () = print "  Exported\n"
+      val () = print ("    precision:    " ^ Int.toString xprecision ^ "\n")
+      val () = print ("    max exponent: " ^ Int.toString xmaxExp ^ "\n")
+      val () = print ("    min exponent: " ^ Int.toString xminExp ^ "\n")
+      val () = print ("    subnormal:    " ^ xdeNorm ^ "\n")
+   end
+
+val () = print "Real32\n"
+structure Z = Basic(structure Real = Real32
+                    structure Pack = PackReal32Little)
+val () = print "Real64\n"
+structure Z = Basic(structure Real = Real64
+                    structure Pack = PackReal64Big)

Added: mlton/trunk/regression/real-basic.x86-darwin.ok
===================================================================
--- mlton/trunk/regression/real-basic.x86-darwin.ok	2009-10-20 14:11:16 UTC (rev 7294)
+++ mlton/trunk/regression/real-basic.x86-darwin.ok	2009-10-20 14:50:23 UTC (rev 7295)
@@ -0,0 +1,32 @@
+Real32
+  Reported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    yes
+  Actual
+    precision:    64
+    max exponent: 128
+    min exponent: ~149
+    subnormal:    yes
+  Exported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    no
+Real64
+  Reported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    yes
+  Actual
+    precision:    64
+    max exponent: 1024
+    min exponent: ~1074
+    subnormal:    yes
+  Exported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    no

Added: mlton/trunk/regression/real-basic.x86-freebsd.ok
===================================================================
--- mlton/trunk/regression/real-basic.x86-freebsd.ok	2009-10-20 14:11:16 UTC (rev 7294)
+++ mlton/trunk/regression/real-basic.x86-freebsd.ok	2009-10-20 14:50:23 UTC (rev 7295)
@@ -0,0 +1,32 @@
+Real32
+  Reported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    yes
+  Actual
+    precision:    64
+    max exponent: 128
+    min exponent: ~149
+    subnormal:    yes
+  Exported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    no
+Real64
+  Reported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    yes
+  Actual
+    precision:    64
+    max exponent: 1024
+    min exponent: ~1074
+    subnormal:    yes
+  Exported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    no

Added: mlton/trunk/regression/real-basic.x86-linux.ok
===================================================================
--- mlton/trunk/regression/real-basic.x86-linux.ok	2009-10-20 14:11:16 UTC (rev 7294)
+++ mlton/trunk/regression/real-basic.x86-linux.ok	2009-10-20 14:50:23 UTC (rev 7295)
@@ -0,0 +1,32 @@
+Real32
+  Reported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    yes
+  Actual
+    precision:    64
+    max exponent: 128
+    min exponent: ~149
+    subnormal:    yes
+  Exported
+    precision:    24
+    max exponent: 128
+    min exponent: ~148
+    subnormal:    no
+Real64
+  Reported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    yes
+  Actual
+    precision:    64
+    max exponent: 1024
+    min exponent: ~1074
+    subnormal:    yes
+  Exported
+    precision:    53
+    max exponent: 1024
+    min exponent: ~1073
+    subnormal:    no




More information about the MLton-commit mailing list