# <2> 设置变量
set X "this is a string, Y=:"
set Y 1.23
puts $X
puts $Y
puts "**********"
puts "$X $Y"
# <3> 数学计算
# [expr {$a - $b}]
# >>>>> eq ne in ni <<<<<<
# > compare two strings for equality (eq) or inequality (ne). and two operators for checking
# > if a string is contained in a list (in) or not (ni). These operators all return 1 (true) or 0 (false).
# > Using these operators ensures that
# > the operands are regarded exclusively as strings (and lists), not as possible numbers:
# >>>>>>>>>>>>>>>>>>>>>>>>
set X 100
set Y 256
set Z [expr {$Y + $X}]
set Z_LABEL "$Y plus $X is "
puts "$Z_LABEL $Z"
puts "The square root of $Y is [expr { sqrt($Y) }]\n"
puts "Because of the precedence rules \"5 + -3 * 4\" is: [expr {-3 * 4 + 5}]"
puts "Because of the parentheses \"(5 + -3) * 4\" is: [expr {(5 + -3) * 4}]"
set A 3
set B 4
puts "The hypotenuse of a triangle: [expr {hypot($A,$B)}]"
#
# The trigonometric functions work with radians ...
#
set pi6 [expr {3.1415926/6.0}]
puts "The sine and cosine of pi/6: [expr {sin($pi6)}] [expr {cos($pi6)}]"
#
# <4> 数组 Working with arrays
#
set a(1) 10
set a(2) 7
set a(3) 17
set b 2
puts "Sum: [expr {$a(1)+$a($b)}]"
# <5> 数的类型
# >>> 整形数相乘除,得到的数如果是浮点型,此浮点型不能被输出,而是以整形输输出
# >>> 如果需要计算结果输出浮点型,有两种方法
# >>> 1. 运算子其中一个为浮点型,如"1."
# >>> 2. 强制类型转换 double (1), tcl中浮点型为double,没有float
puts "1/2 is [expr {1/2}]"
puts "-1/2 is [expr {-1/2}]"
puts "1/2 is [expr {1./2}]"
puts "1/3 is [expr {1./3}]"
puts "1/3 is [expr {double(1)/3}]"