expr.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:16k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-2000 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: expr.n,v 1.10.2.2 2004/10/27 09:35:38 dkf Exp $
- '"
- .so man.macros
- .TH expr n 8.4 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- expr - Evaluate an expression
- .SH SYNOPSIS
- fBexpr fIarg fR?fIarg arg ...fR?
- .BE
- .SH DESCRIPTION
- .PP
- Concatenates fIargfRs (adding separator spaces between them),
- evaluates the result as a Tcl expression, and returns the value.
- The operators permitted in Tcl expressions are a subset of
- the operators permitted in C expressions, and they have the
- same meaning and precedence as the corresponding C operators.
- Expressions almost always yield numeric results
- (integer or floating-point values).
- For example, the expression
- .CS
- fBexpr 8.2 + 6fR
- .CE
- evaluates to 14.2.
- Tcl expressions differ from C expressions in the way that
- operands are specified. Also, Tcl expressions support
- non-numeric operands and string comparisons.
- .SH OPERANDS
- .PP
- A Tcl expression consists of a combination of operands, operators,
- and parentheses.
- White space may be used between the operands and operators and
- parentheses; it is ignored by the expression's instructions.
- Where possible, operands are interpreted as integer values.
- Integer values may be specified in decimal (the normal case), in octal (if the
- first character of the operand is fB0fR), or in hexadecimal (if the first
- two characters of the operand are fB0xfR).
- If an operand does not have one of the integer formats given
- above, then it is treated as a floating-point number if that is
- possible. Floating-point numbers may be specified in any of the
- ways accepted by an ANSI-compliant C compiler (except that the
- fBffR, fBFfR, fBlfR, and fBLfR suffixes will not be permitted in
- most installations). For example, all of the
- following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.
- If no numeric interpretation is possible (note that all literal
- operands that are not numeric or boolean must be quoted with either
- braces or with double quotes), then an operand is left as a string
- (and only a limited set of operators may be applied to it).
- .PP
- .VS 8.4
- On 32-bit systems, integer values MAX_INT (0x7FFFFFFF) and MIN_INT
- (-0x80000000) will be represented as 32-bit values, and integer values
- outside that range will be represented as 64-bit values (if that is
- possible at all.)
- .VE 8.4
- .PP
- Operands may be specified in any of the following ways:
- .IP [1]
- As a numeric value, either integer or floating-point.
- .IP [2]
- As a boolean value, using any form understood by fBstring is booleanfR.
- .IP [3]
- As a Tcl variable, using standard fB$fR notation.
- The variable's value will be used as the operand.
- .IP [4]
- As a string enclosed in double-quotes.
- The expression parser will perform backslash, variable, and
- command substitutions on the information between the quotes,
- and use the resulting value as the operand
- .IP [5]
- As a string enclosed in braces.
- The characters between the open brace and matching close brace
- will be used as the operand without any substitutions.
- .IP [6]
- As a Tcl command enclosed in brackets.
- The command will be executed and its result will be used as
- the operand.
- .IP [7]
- As a mathematical function whose arguments have any of the above
- forms for operands, such as fBsin($x)fR. See below for a list of defined
- functions.
- .LP
- Where the above substitutions occur (e.g. inside quoted strings), they
- are performed by the expression's instructions.
- However, the command parser may already have performed one round of
- substitution before the expression processor was called.
- As discussed below, it is usually best to enclose expressions
- in braces to prevent the command parser from performing substitutions
- on the contents.
- .PP
- For some examples of simple expressions, suppose the variable
- fBafR has the value 3 and
- the variable fBbfR has the value 6.
- Then the command on the left side of each of the lines below
- will produce the value on the right side of the line:
- .CS
- .ta 6c
- fBexpr 3.1 + $a 6.1
- expr 2 + "$a.$b" 5.6
- expr 4*[llength "6 2"] 8
- expr {{word one} < "word $a"} 0fR
- .CE
- .SH OPERATORS
- .PP
- The valid operators are listed below, grouped in decreasing order
- of precedence:
- .TP 20
- fB- + ~ !fR
- Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operators
- may be applied to string operands, and bit-wise NOT may be
- applied only to integers.
- .TP 20
- fB* / %fR
- Multiply, divide, remainder. None of these operators may be
- applied to string operands, and remainder may be applied only
- to integers.
- The remainder will always have the same sign as the divisor and
- an absolute value smaller than the divisor.
- .TP 20
- fB+ -fR
- Add and subtract. Valid for any numeric operands.
- .TP 20
- fB<<