It is also worth noting that numbers that start with a 0 are treated as base 8 numbers and not base 10.
For exapmle, try the follwing at the hcitcl prompt
hcitcl>if { [expr 77 == 077] } { echo TRUE } else {echo FALSE}
FALSE
hcitcl>if { [expr 77 == 77] } { echo TRUE } else {echo FALSE}
TRUE
Here is an example of a generic TCL proc that I call within other procs like TPS of XLT procs to compare if 2 numbers are equal that gets around this problem:
# Begin Module Header ==========================================================
#
#——
# Name:
#——
#
# oth_nequal.tcl
#
#———
# Purpose:
#———
#
# Compare 2 numbers to see if they are equal.
#
#——–
# Inputs:
#——–
#
# n1 = fist number to use for comparison
# n2 = second number to use for comparision
#
#———
# Outputs:
#———
#
# returns 1 if the two input numbers are equal
# returns 0 if the two input numbers are not equal
#
#——-
# Notes:
#——-
#
# This is not a robust module.
# It is expected that the input strings are reasonable numbers like:
#
# “28”
# “+00028 ”
# “- 028 ”
# ” 28.10″
#
# Spaces and leading zeros will be handled but not bogus numbers
#
# TCL will freak out with a syntax error if you try to use expr
# to compare 2 numbers if either of them have leading zeros, so
# this module will strip off leading zeros before comparing the two input numbers.
#
#———
# History:
#———
#
# 2000.05.24 Russ Ross
# – wrote initial version
#
# End Module Header ============================================================
proc oth_nequal { n1 n2 } {
#——————————————
# remove any spaces from the number strings
#——————————————
regsub -all “x20” $n1 “” n1
regsub -all “x20” $n2 “” n2
#—————————-
# trim plus sign if it exists
# and trim leading zeros
#—————————-
regsub {+*[0]*} $n1 “” n1
regsub {+*[0]*} $n2 “” n2
#—————————————
# keep minus sign and trim leading zeros
#—————————————
regsub {-[0]*} $n1 “-” n1
regsub {-[0]*} $n2 “-” n2
#———————————
# compare the numbers for equality
#———————————
if { [expr $n1 == $n2] } {
return 1
} else {
return 0
}
}
Russ Ross
RussRoss318@gmail.com