Two procedures from the bag of utilities used by Jeff Hobbs. The first computes the largest integer supported by Tcl on the platform it is run on. The second computes the number of bits in that integer.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ```
# largest_int --
# Finds the largest recognized int in Tcl for the platform
# Arguments:
# none
# Results:
# Returns the largest allowed value for an int (for exprs and stuff)
#
proc largest_int {} {
set int 1
set exp 7; # assume we get at least 8 bits
while {$int > 0} { set int [expr {1 << [incr exp]}] }
expr {$int-1}
}
# int_bits --
# Finds the number of bits in an int
# Arguments:
# none
# Results:
# Returns the numbers of bits in an int
#
proc int_bits {} {
set int 1
set exp 7; # assume we get at least 8 bits
while {$int > 0} { set int [expr {1 << [incr exp]}] }
# pop up one more, since we start at 0
incr exp
}
``` |

For most modern computers, the following one-liners also work:

You need tcl 8.4 for the first one.