returned to the traditional RND() function
This commit is contained in:
@@ -75,12 +75,12 @@ proc lttb_eval {lttb_ex} {
|
||||
if {[string is digit $lttb_ex]} {return [lttb_norm $(int($lttb_ex))]}
|
||||
# pass 1: variable and parentheses substitution
|
||||
global vars
|
||||
regsub -all -nocase -- {RND} $lttb_ex {0$} lttb_ex
|
||||
lassign {{(((} {}} pre_ex prevc
|
||||
foreach c [split $lttb_ex {}] {
|
||||
set outc {}
|
||||
if {[string is digit $c]} {set outc $c}
|
||||
if {[string is digit $c] || $c eq {$}} {set outc $c}
|
||||
if {[string is upper $c]} {set outc $vars($c)}
|
||||
if {$c eq "$"} {set outc [rand 0 10000]}
|
||||
if {$c eq "("} {set outc {(((}}
|
||||
if {$c eq ")"} {set outc {)))}}
|
||||
if {$c eq "*" || $c eq "/"} {set outc [string cat {)} $c {(}]}
|
||||
@@ -102,16 +102,17 @@ proc lttb_eval {lttb_ex} {
|
||||
set v2 [_lpop valstack]
|
||||
set v1 [_lpop valstack]
|
||||
switch -exact -- $op {
|
||||
"+" { set res $($v1 + $v2) }
|
||||
"-" { set res $($v1 - $v2) }
|
||||
"*" { set res $($v1 * $v2) }
|
||||
"/" { if {$v2 != 0} {set res $(int($v1 / $v2))} }
|
||||
{$} { set res [rand 0 $(($v2 + 32768) % 32768)] }
|
||||
{+} { set res $($v1 + $v2) }
|
||||
{-} { set res $($v1 - $v2) }
|
||||
{*} { set res $($v1 * $v2) }
|
||||
{/} { if {$v2 != 0} {set res $(int($v1 / $v2))} }
|
||||
default { error "Unknown operator: $op" }
|
||||
}
|
||||
lappend valstack [lttb_norm $res]
|
||||
}
|
||||
lassign {{} {} {}} valbuf valstack opstack
|
||||
set precmap {+ 1 - 1 * 2 / 2}
|
||||
set precmap {+ 1 - 1 * 2 / 2 $ 3}
|
||||
foreach c [split $pre_ex {}] {
|
||||
if {[string is space $c]} {continue}
|
||||
if {[string is digit $c]} {
|
||||
@@ -128,7 +129,7 @@ proc lttb_eval {lttb_ex} {
|
||||
eval_helper valstack opstack
|
||||
}
|
||||
if {[lindex $opstack end] eq "("} {_lpop opstack}
|
||||
} elseif {$c in {+ - * /}} {
|
||||
} elseif {$c in {+ - * / $}} {
|
||||
set prec $precmap($c)
|
||||
while {[llength $opstack] > 0} {
|
||||
set top_op [lindex $opstack end]
|
||||
|
||||
Reference in New Issue
Block a user