changeset 285:e89076c41c39

toString for float and bool
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 10:20:42 -0400
parents 77a28e7430bf
children ffe5b01908ae
files include/urweb.h lib/basis.urs src/c/urweb.c src/prim.sml tests/toString.ur
diffstat 5 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb.h	Sun Sep 07 10:13:02 2008 -0400
+++ b/include/urweb.h	Sun Sep 07 10:20:42 2008 -0400
@@ -69,3 +69,5 @@
 char *lw_Basis_ensqlBool(lw_Basis_bool);
 
 lw_Basis_string lw_Basis_intToString(lw_context, lw_Basis_int);
+lw_Basis_string lw_Basis_floatToString(lw_context, lw_Basis_float);
+lw_Basis_string lw_Basis_boolToString(lw_context, lw_Basis_bool);
--- a/lib/basis.urs	Sun Sep 07 10:13:02 2008 -0400
+++ b/lib/basis.urs	Sun Sep 07 10:20:42 2008 -0400
@@ -24,7 +24,8 @@
 val strcat : string -> string -> string
 
 val intToString : int -> string
-
+val floatToString : float -> string
+val boolToString : bool -> string
 
 
 (** SQL *)
--- a/src/c/urweb.c	Sun Sep 07 10:13:02 2008 -0400
+++ b/src/c/urweb.c	Sun Sep 07 10:20:42 2008 -0400
@@ -681,3 +681,21 @@
   ctx->heap_front += len+1;
   return r;
 }
+
+lw_Basis_string lw_Basis_floatToString(lw_context ctx, lw_Basis_float n) {
+  int len;
+  char *r;
+
+  lw_check_heap(ctx, FLOATS_MAX);
+  r = ctx->heap_front;
+  sprintf(r, "%g%n", n, &len);
+  ctx->heap_front += len+1;
+  return r;
+}
+
+lw_Basis_string lw_Basis_boolToString(lw_context ctx, lw_Basis_bool b) {
+  if (b == lw_Basis_False)
+    return "False";
+  else
+    return "True";
+}
--- a/src/prim.sml	Sun Sep 07 10:13:02 2008 -0400
+++ b/src/prim.sml	Sun Sep 07 10:20:42 2008 -0400
@@ -49,9 +49,9 @@
 
 fun float2s n =
     if Real64.compare (n, Real64.fromInt 0) = LESS then
-        "-" ^ Real64.toString (Real64.~ n) ^ "L"
+        "-" ^ Real64.toString (Real64.~ n)
     else
-        Real64.toString n ^ "L"
+        Real64.toString n
 
 fun p_t_GCC t =
     case t of
--- a/tests/toString.ur	Sun Sep 07 10:13:02 2008 -0400
+++ b/tests/toString.ur	Sun Sep 07 10:20:42 2008 -0400
@@ -1,3 +1,5 @@
 fun main () : transaction page = return <html><body>
-        6 = {cdata (intToString 6)}
+        6 = {cdata (intToString 6)}<br/>
+        12.34 = {cdata (floatToString 12.34)}<br/>
+        False = {cdata (boolToString False)}<br/>
 </body></html>