Version 8 of **

Updated 2009-05-26 22:02:20 by ZB

expr "raise to power" operator, similar to pow function

Returns an integer value if both arguments are integers, and double-precision floating-point otherwise.

The left operand may be any integer from Tcl's unlimited integer range.

The right operand is limited to a max integer value of 268435455 (0xfffffff) (28 bits). (Unless the left operand is -1, 0, or 1, so that the answer is trivial).

Expect to wait a long while for [expr 2**0xfffffff] to return.

During early 2009, a thread broke out in the comp.lang.tcl usenet group discussing the observation that Tcl's calculation for

puts [expr {-2**2}]

surprised someone who was expecting the same results as algebra (or even perl). Instead of the results being -4 , Tcl returns 4. The reason has to do with the operator precendence between the - and ** operators.

ZB Either I can't count - feel free to correct me in such case - or indeed TCL is right: (-2)^2 = (-2)*(-2) = 4 Why such "surprise"?