summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-05-29 09:44:44 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-05-29 09:44:44 (GMT)
commit3be8c207009de29d1b986abc9e11c9815a42beec (patch)
treebaf06272c14a5cf1c030debb20781ab4068243bb /doc
parent8d944280e1616ab92d470c999c5c1b98bf97908d (diff)
downloadtcl-3be8c207009de29d1b986abc9e11c9815a42beec.zip
tcl-3be8c207009de29d1b986abc9e11c9815a42beec.tar.gz
tcl-3be8c207009de29d1b986abc9e11c9815a42beec.tar.bz2
[Bug 2931407]: Clarified semantics of division and remainder operators.
Diffstat (limited to 'doc')
-rw-r--r--doc/expr.n15
-rw-r--r--doc/mathop.n16
2 files changed, 25 insertions, 6 deletions
diff --git a/doc/expr.n b/doc/expr.n
index 177e127..dbc9026 100644
--- a/doc/expr.n
+++ b/doc/expr.n
@@ -131,7 +131,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
Add and subtract. Valid for any numeric operands.
diff --git a/doc/mathop.n b/doc/mathop.n
index 5a6ba4e..5757f87 100644
--- a/doc/mathop.n
+++ b/doc/mathop.n
@@ -126,13 +126,19 @@ will be an integer.
.TP
\fB%\fR \fInumber number\fR
.
-Returns the integral modulus of the first argument with respect to the second.
-Each \fInumber\fR must have an integral value. Note that Tcl defines this
-operation exactly even for negative numbers, so that the following equality
-holds true:
+Returns the integral modulus (i.e., remainder) of the first argument
+with respect to the second.
+Each \fInumber\fR must have an integral value.
+Also, the sign of the result will be the same as the sign of the second
+\fInumber\fR, which must not be zero.
.RS
+.PP
+Note that Tcl defines this operation exactly even for negative numbers, so
+that the following command returns a true value (omitting the namespace for
+clarity):
+.PP
.CS
-(\fIx \fB/ \fIy\fR) \fB* \fIy \fB== \fIx \fB-\fR (\fIx \fB% \fIy\fR)
+\fB==\fR [\fB*\fR [\fB/\fI x y\fR] \fIy\fR] [\fB-\fI x\fR [\fB%\fI x y\fR]]
.CE
.RE
.TP