# HG changeset patch # User Adam Chlipala # Date 1318109038 14400 # Node ID f403e129c276e06a1d6936898531689b3528feb6 # Parent c7d0328ba777d9461f7cddf0e5b4384b4007bb10 Primitive int/float functions: ceil, float, round, trunc diff -r c7d0328ba777 -r f403e129c276 include/urweb.h --- a/include/urweb.h Sat Oct 08 14:16:13 2011 -0400 +++ b/include/urweb.h Sat Oct 08 17:23:58 2011 -0400 @@ -348,4 +348,9 @@ uw_Basis_string uw_Basis_fresh(uw_context); +uw_Basis_float uw_Basis_floatFromInt(uw_context, uw_Basis_int); +uw_Basis_int uw_Basis_ceil(uw_context, uw_Basis_float); +uw_Basis_int uw_Basis_trunc(uw_context, uw_Basis_float); +uw_Basis_int uw_Basis_round(uw_context, uw_Basis_float); + #endif diff -r c7d0328ba777 -r f403e129c276 lib/js/urweb.js --- a/lib/js/urweb.js Sat Oct 08 14:16:13 2011 -0400 +++ b/lib/js/urweb.js Sat Oct 08 17:23:58 2011 -0400 @@ -93,6 +93,25 @@ } +// Floats + +function float(n) { + return n; +} + +function trunc(n) { + return ~~n; +} + +function ceil(n) { + return Math.ceil(n); +} + +function round(n) { + return Math.round(n); +} + + // Time function showTime(tm) { diff -r c7d0328ba777 -r f403e129c276 lib/ur/basis.urs --- a/lib/ur/basis.urs Sat Oct 08 14:16:13 2011 -0400 +++ b/lib/ur/basis.urs Sat Oct 08 17:23:58 2011 -0400 @@ -145,6 +145,14 @@ val current : t ::: Type -> signal t -> transaction t +(** * Floats *) + +val float : int -> float +val ceil : float -> int +val trunc : float -> int +val round : float -> int + + (** * Time *) val now : transaction time diff -r c7d0328ba777 -r f403e129c276 src/c/urweb.c --- a/src/c/urweb.c Sat Oct 08 14:16:13 2011 -0400 +++ b/src/c/urweb.c Sat Oct 08 17:23:58 2011 -0400 @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -3956,3 +3957,19 @@ uw_Basis_string uw_Basis_fresh(uw_context ctx) { return uw_Basis_htmlifyInt(ctx, ctx->nextId++); } + +uw_Basis_float uw_Basis_floatFromInt(uw_context ctx, uw_Basis_int n) { + return n; +} + +uw_Basis_int uw_Basis_ceil(uw_context ctx, uw_Basis_float n) { + return ceil(n); +} + +uw_Basis_int uw_Basis_trunc(uw_context ctx, uw_Basis_float n) { + return trunc(n); +} + +uw_Basis_int uw_Basis_round(uw_context ctx, uw_Basis_float n) { + return round(n); +} diff -r c7d0328ba777 -r f403e129c276 src/monoize.sml --- a/src/monoize.sml Sat Oct 08 14:16:13 2011 -0400 +++ b/src/monoize.sml Sat Oct 08 17:23:58 2011 -0400 @@ -1356,6 +1356,13 @@ end | L.EFfiApp ("Basis", "recv", _) => poly () + | L.EFfiApp ("Basis", "float", [e]) => + let + val (e, fm) = monoExp (env, st, fm) e + in + ((L'.EFfiApp ("Basis", "floatFromInt", [e]), loc), fm) + end + | L.EFfiApp ("Basis", "sleep", [n]) => let val (n, fm) = monoExp (env, st, fm) n diff -r c7d0328ba777 -r f403e129c276 src/settings.sml --- a/src/settings.sml Sat Oct 08 14:16:13 2011 -0400 +++ b/src/settings.sml Sat Oct 08 17:23:58 2011 -0400 @@ -270,6 +270,11 @@ ("debug", "alert"), ("naughtyDebug", "alert"), + ("floatFromInt", "float"), + ("ceil", "ceil"), + ("trunc", "trunc"), + ("round", "round"), + ("now", "now"), ("timeToString", "showTime"), ("htmlifyTime", "showTime"),