## Numbers

part of Tcl for Web Nerds by Hal Abelson, Philip Greenspun, and Lydia Sandon; updated July 2011
Arithmetic is not done directly by the Tcl interpreter. It is done by calling the C library using the `expr` command on arthmetic expressions. The detailed parsing rules for arithmetic expressions depend on the particular Unix implementation, but they are more or less like in C.

Here are some examples:

```# integer division truncates % expr 7 / 2 3 # the percent sign is used to compute integer remainder % expr 7%2 # floating point propagates % expr 7.0 / 2 3.5 % expr sin(.5)+cos(.9) 1.10103550687 % # a zero in front of number means to interpret as octal % expr 017 + 01 16 % # a 0x in front means to interpret as hex % expr 0xA + 1 11 % # numbers can be treated like strings! % string length 100.34 6 % string range 100.34 0 2 100 ```
More: See http://www.tcl.tk/man/tcl8.4/TclCmd/expr.htm.

### Reference

Here are the numeric functions included in Tcl. (Details may vary depending on your Unix implementation of `expr`.) ``` abs(x) asin(x) acos(x) atan(x) atan2(y,x) atan2 returns the angle theta of the polar coordinates returned when (x,y) is converted to (r, theta). ceil(x) cos(x) cosh(x) double(x)returns x as a double or floating point. exp(x)returns e^x floor(x) fmod(x,y)returns the floating point remainder of x/y. hypot(x,y)returns the square root of the sum of x squared plus y squared, the length of the line from (0,0) to (x,y). int(x)truncates x to an integer. log(x)returns the natural log of x. log10(x)returns log base 10 of x. pow(x,y)returns x to the y power. round(x) sin(x) sinh(x) sqrt(x) tan(x) tanh(x) ```

Continue on to Control structure