Tcl Mathematical Expressions
In Tcl, mathematical expressions are evaluated using the expr command. This command works with integers, floating point values and logical (Boolean) values. There are many arithmetic operators and built-in math functions in Tcl.
For more in-depth explanations and a complete listing, referred to http://www.tcl.tk/man/ or to a Tcl/Tk handbook.
set circumference [expr 2*(2*asin(1.0))*6.0]
puts $circumference
37.6991118431
set pi [expr 2*asin(1.0)]
set radius 6.0
set circumference [expr 2*$pi*$radius]
puts $circumference
37.6991118431
set pi [expr 2*asin(1.0)]
set radius "radius"
set circumference [expr 2*$pi*[string length $radius]]
puts $circumference
37.6991118431
set using_integer [expr 1/9]
set using_float [expr 1/9.]
puts $using_int
0
puts $using_float
0.111111111111
set circumference [expr {2*(2*asin(1.0))*6.0}]
set pi [expr {2*asin(1.0)}]
set radius 6.0
set circumference [expr {2*$pi*$radius}]
set var1 [expr {sqrt(2.0)}]
puts $var1
1.41421356237
set var2 [expr $var1 * $var1]
puts $var2
1.99999999999
set var2 [expr {$var1 * $var1}]
puts $var2
2.0
puts $tcl_precision
12
set var1 [expr 1/9.]
0.111111111111
set tcl_precision 17
puts $tcl_precision
17
set var1 [expr 1/9.]
0.11111111111111111