NAME

integer - Evaluate a pure integer expression

SYNOPSIS

integer arg ?arg arg ...?

DESCRIPTION

Evaluates the arguments as an arithmetic expression and returns the value.

The result of an integer command should be treated only as a string in Tcl commands. One needs to be wary of commands which assume the use of expr such as the if, for and while tests. Neither can the result of a integer command be used safely in expr. The command is not intended for number crunching applications but rather as a vehicle for applications in number theory, function theory and artificial intelligence.

Typically integer expressions will be constructed by a Tcl script and executed using a command like:
set x [eval integer $intexpr].

ARGUMENTS

An argument may be an operand, an operator or a parenthesis.

An operand is of canonical Tcl decimal integer form; that is described by the regular expressions 0 or [1-9][0-9]* or -[1-9][0-9]*. The maximum length of a long integer is determined by system resources such as memory.

An operator may be one of + - * / or % . The three types of operator, additive ( + - ) , multiplicative ( * / ), and modulus (%), must be grouped seperately by parentheses. The five operators return signed integers according to the same rules for expr. Within the additive group the + operators must preceed the - operators and similarly in the multiplicative group the * operators must preceed the / operators. The modulus operator % may not be grouped associatively. The expression is evaluated from left to right. The group ( $a1 + $a2 - $a3 - $a4 - ... - $an ) is evaluated as ($a1 + $a2 - ( $a3 + $a4 + ... + $an ) ) and similarly for the multiplicative group. For the multiplicative group this ensures that multiplications are done before any divisions so that whole divisions are performed where ever possible. This is a much more restricted form of arithmetic expression syntax than in C expressions for instance, as it is designed for people who do not know about syntactic grammar conventions.