Author: coke
Date: Sat Jan  6 19:19:24 2007
New Revision: 16452

Modified:
   trunk/   (props changed)
   trunk/languages/tcl/src/grammar/expr/functions.pir
   trunk/languages/tcl/t/cmd_expr.t

Log:
[tcl] - implement [expr floor()]


Modified: trunk/languages/tcl/src/grammar/expr/functions.pir
==============================================================================
--- trunk/languages/tcl/src/grammar/expr/functions.pir  (original)
+++ trunk/languages/tcl/src/grammar/expr/functions.pir  Sat Jan  6 19:19:24 2007
@@ -257,6 +257,40 @@
 .end
 
 .sub '&floor' 
+    .param pmc a
+
+    .local pmc result
+
+    .local pmc __number
+    __number = get_root_global ['_tcl'], '__number'
+
+    push_eh is_string
+      result = __number(a)
+    clear_eh
+
+    if result >= 0 goto positive
+      
+negative: 
+    $I0 = result
+    dec $I0
+    $N0 = $I0
+    $P0 = new .TclFloat
+    $P0 = $N0
+    .return ($P0) 
+
+positive: 
+    $I0 = result
+    $N0 = $I0
+    $P0 = new .TclFloat
+    $P0 = $N0
+    .return ($P0)
+
+is_string:
+    $S0 = 'expected floating-point number but got "'
+    $S1 = a
+    $S0 .= $S1
+    $S0 .= '"'
+    tcl_error $S0
 .end
 
 .sub '&int'

Modified: trunk/languages/tcl/t/cmd_expr.t
==============================================================================
--- trunk/languages/tcl/t/cmd_expr.t    (original)
+++ trunk/languages/tcl/t/cmd_expr.t    Sat Jan  6 19:19:24 2007
@@ -7,7 +7,7 @@
 __DATA__
 
 source lib/test_more.tcl
-plan 286
+plan 291
 
 # namespace
 namespace eval test { variable x 5 }
@@ -225,6 +225,9 @@
 is [expr entier(3)]     3
 is [expr entier(3.5)]   3
 is [expr exp(1)]        2.718281828459045
+is [expr floor(0.1)]    0.0
+is [expr floor(0.0)]    0.0
+is [expr floor(-0.1)]   -1.0
 is [expr fmod(3,2)]     1.0
 is [expr fmod(-4, -1)] -0.0 {} $TODO
 is [expr hypot(3,4)]    5.0
@@ -283,7 +286,7 @@
 
 # unary math functions, invalid string ops.
 set function_list \
-  [list acos asin atan cos cosh exp log log10 sin sinh sqrt tan tanh]
+  [list acos asin atan cos cosh exp floor log log10 sin sinh sqrt tan tanh]
 foreach function $function_list {
   eval_is "expr ${function}(\"a\")" \
     {expected floating-point number but got "a"} \

Reply via email to