changeset 1468:4d04cb89649b

Proper C pretty-printing of floats in scientific notation
author Adam Chlipala <adam@chlipala.net>
date Tue, 31 May 2011 07:44:52 -0400 (2011-05-31)
parents 8fce85939259
children a354b306f948
files src/prim.sml tests/float.ur tests/float.urs
diffstat 3 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/prim.sml	Mon May 30 09:31:50 2011 -0400
+++ b/src/prim.sml	Tue May 31 07:44:52 2011 -0400
@@ -55,11 +55,7 @@
     else
         Int64.toString n
 
-fun float2s n =
-    if Real64.compare (n, Real64.fromInt 0) = LESS then
-        "-" ^ Real64.toString (Real64.~ n)
-    else
-        Real64.toString n
+val float2s = String.translate (fn #"~" => "-" | ch => str ch) o Real64.toString
 
 fun toString t =
     case t of
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/float.ur	Tue May 31 07:44:52 2011 -0400
@@ -0,0 +1,6 @@
+fun main () =
+  let
+    val x = 0.001 * 50.0
+  in
+    return <xml><body>{[x]}</body></xml>
+  end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/float.urs	Tue May 31 07:44:52 2011 -0400
@@ -0,0 +1,1 @@
+val main : unit -> transaction page