diff options
author | dgp <dgp@users.sourceforge.net> | 2012-07-19 15:08:23 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2012-07-19 15:08:23 (GMT) |
commit | 5bf41fe2eb79370375e30562f224f88cb98b33a5 (patch) | |
tree | d94b750cf65002836c0ef8fe10e84b9cd2b4aea6 /doc/expr.n | |
parent | bc2133334d0fb3580be3b1cd65ed85b991887e68 (diff) | |
parent | 830b7864006fbd3ee3ac120aa17bf2416483a08d (diff) | |
download | tcl-5bf41fe2eb79370375e30562f224f88cb98b33a5.zip tcl-5bf41fe2eb79370375e30562f224f88cb98b33a5.tar.gz tcl-5bf41fe2eb79370375e30562f224f88cb98b33a5.tar.bz2 |
merge trunk
Diffstat (limited to 'doc/expr.n')
-rw-r--r-- | doc/expr.n | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -134,7 +134,20 @@ 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. +an absolute value smaller than the absolute value of the divisor. +.RS +.PP +When applied to integers, the division and remainder operators can be +considered to partition the number line into a sequence of equal-sized +adjacent non-overlapping pieces where each piece is the size of the divisor; +the division result identifies which piece the divisor lay within, and the +remainder result identifies where within that piece the divisor lay. A +consequence of this is that the result of +.QW "-57 \fB/\fR 10" +is always -6, and the result of +.QW "-57 \fB%\fR 10" +is always 3. +.RE .TP 20 \fB+\0\0\-\fR . @@ -326,6 +339,7 @@ returns \fB4.0\fR, not \fB4\fR. String values may be used as operands of the comparison operators, although the expression evaluator tries to do comparisons as integer or floating-point when it can, +i.e., when all arguments to the operator allow numeric interpretations, except in the case of the \fBeq\fR and \fBne\fR operators. If one of the operands of a comparison is a string and the other has a numeric value, a canonical string representation of the numeric @@ -337,12 +351,11 @@ is that produced by the \fB%g\fR format specifier of Tcl's .PP .CS \fBexpr\fR {"0x03" > "2"} -\fBexpr\fR {"0y" < "0x12"} +\fBexpr\fR {"0y" > "0x12"} .CE .PP both return 1. The first comparison is done using integer -comparison, and the second is done using string comparison after -the second operand is converted to the string \fB18\fR. +comparison, and the second is done using string comparison. Because of Tcl's tendency to treat values as numbers whenever possible, it is not generally a good idea to use operators like \fB==\fR when you really want string comparison and the values of the |