summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2006-04-26 04:41:08 (GMT)
committerdgp <dgp@users.sourceforge.net>2006-04-26 04:41:08 (GMT)
commitf6d77956fdaaa7ca44ba08221d72bbec06bc7709 (patch)
tree9795486d00c14f4474da8e205fbafad357a55a7c
parentb86eb4a0d9739e188fb6dbd9a2ab0823c835fad4 (diff)
downloadtcl-f6d77956fdaaa7ca44ba08221d72bbec06bc7709.zip
tcl-f6d77956fdaaa7ca44ba08221d72bbec06bc7709.tar.gz
tcl-f6d77956fdaaa7ca44ba08221d72bbec06bc7709.tar.bz2
* doc/DoubleObj.3: More doc updates for TIP 237.
* doc/expr.n: * doc/format.n: * doc/mathfunc.n: * doc/scan.n: * doc/string.n:
-rw-r--r--ChangeLog3
-rw-r--r--doc/expr.n72
-rw-r--r--doc/mathfunc.n72
-rw-r--r--doc/scan.n6
-rw-r--r--doc/string.n8
5 files changed, 101 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 852b0ec..5d06340 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,11 @@
2006-04-25 Don Porter <dgp@users.sourceforge.net>
* doc/DoubleObj.3: More doc updates for TIP 237.
+ * doc/expr.n:
* doc/format.n:
+ * doc/mathfunc.n:
* doc/scan.n:
+ * doc/string.n:
* generic/tclScan.c: [scan $s %u] is documented to accept only
* tests/scan.test: decimal formatted integers. Fixed code to
diff --git a/doc/expr.n b/doc/expr.n
index 2fb328c..880ab0e 100644
--- a/doc/expr.n
+++ b/doc/expr.n
@@ -6,7 +6,7 @@
'\" 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.21 2005/06/09 14:24:06 dkf Exp $
+'\" RCS: @(#) $Id: expr.n,v 1.22 2006/04/26 04:41:10 dgp Exp $
'\"
.so man.macros
.TH expr n 8.5 Tcl "Tcl Built-In Commands"
@@ -22,9 +22,10 @@ expr \- Evaluate an expression
.PP
Concatenates \fIarg\fRs (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.
+The operators permitted in Tcl expressions include a subset of
+the operators permitted in C expressions. For those operators
+common to both Tcl and C, Tcl applies 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
@@ -34,7 +35,8 @@ For example, the expression
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.
+non-numeric operands and string comparisons, as well as some
+additional operators not found in C.
.SS OPERANDS
.PP
A Tcl expression consists of a combination of operands, operators,
@@ -42,26 +44,29 @@ 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 \fB0\fR), or in hexadecimal (if the first
-two characters of the operand are \fB0x\fR).
+.VS 8.5
+Integer values may be specified in decimal (the normal case), in binary
+(if the first two characters of the operand are \fB0b\fR), in octal
+(if the first two characters of the operand are \fB0o\fR), or in hexadecimal
+(if the first two characters of the operand are \fB0x\fR). For
+compatibility with older Tcl releases, an octal integer value is also
+indicated simply when the first character of the operand is \fB0\fR,
+whether or not the second character is also \fBo\fR.
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
-\fBf\fR, \fBF\fR, \fBl\fR, and \fBL\fR suffixes will not be permitted in
-most installations). For example, all of the
+possible. Floating-point numbers may be specified in any of several
+common formats making use of the decimal digits, the decimal point \fB.\fR,
+the characters \fBe\fR or \fBE\fR indicating scientific notation, and
+the sign characters \fB+\fR or \fB-\fR. For example, all of the
following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.
+Also recognized as floating point values are the strings \fBInf\fR
+and \fBNaN\fR making use of any case for each character.
+.VE 8.5
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
-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.)
-.PP
Operands may be specified in any of the following ways:
.IP [1]
As a numeric value, either integer or floating-point.
@@ -235,16 +240,23 @@ available by default.
.VE 8.5
.SS "TYPES, OVERFLOW, AND PRECISION"
.PP
-All internal computations involving integers are done with the C type
-\fIlong\fR, and all internal computations involving floating-point are
+.VS 8.5
+All internal computations involving integers are done calling on the
+LibTomMath multiple precision integer library as required so that all
+integer calculations are performed exactly. Note that in Tcl releases
+prior to 8.5, integer calculations were performed with one of the C types
+\fIlong int\fR or \fITcl_WideInt\fR, causing implicit range truncation
+in those calculations where values overflowed the range of those types.
+Any code that relied on these implicit trunctions will need to explicitly
+add \fBint()\fR or \fBwide()\fR function calls to expressions at the points
+where such truncation is required to take place.
+.VE 8.5
+.PP
+All internal computations involving floating-point are
done with the C type \fIdouble\fR.
When converting a string to floating-point, exponent overflow is
-detected and results in a Tcl error.
-For conversion to integer from string, detection of overflow depends
-on the behavior of some routines in the local C library, so it should
-be regarded as unreliable.
-In any case, integer overflow and underflow are generally not detected
-reliably for intermediate results. Floating-point overflow and underflow
+detected and results in the \fIdouble\fR value of \fBInf\fR or
+\fB-Inf\fR as appropriate. Floating-point overflow and underflow
are detected to the degree supported by the hardware, which is generally
pretty reliable.
.PP
@@ -276,10 +288,12 @@ although the expression evaluator tries to do comparisons as integer
or floating-point when it can,
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, the numeric operand is converted back to
-a string using the C \fIsprintf\fR format specifier
-\fB%d\fR for integers and \fB%g\fR for floating-point values.
-For example, the commands
+has a numeric value, a canonical string representation of the numeric
+operand value is generated to compare with the string operand.
+Canonical string representation for integer values is a decimal string
+format. Canonical string representation for floating-point values
+is that produced by the \fB%g\fR format specifier of Tcl's
+\fBformat\fR command. For example, the commands
.CS
\fBexpr {"0x03" > "2"}\fR
\fBexpr {"0y" < "0x12"}\fR
diff --git a/doc/mathfunc.n b/doc/mathfunc.n
index b66f1a0..21d0371 100644
--- a/doc/mathfunc.n
+++ b/doc/mathfunc.n
@@ -6,7 +6,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: mathfunc.n,v 1.8 2005/12/12 16:06:50 kennykb Exp $
+'\" RCS: @(#) $Id: mathfunc.n,v 1.9 2006/04/26 04:41:10 dgp Exp $
'\"
.so man.macros
.TH mathfunc n 8.5 Tcl "Tcl Mathematical Functions"
@@ -37,6 +37,10 @@ package require \fBTcl 8.5\fR
.br
\fB::tcl::mathfunc::double\fR \fIarg\fR
.br
+.VS 8.5
+\fB::tcl::mathfunc::entier\fR \fIarg\fR
+.br
+.VE 8.5
\fB::tcl::mathfunc::exp\fR \fIarg\fR
.br
\fB::tcl::mathfunc::floor\fR \fIarg\fR
@@ -93,12 +97,12 @@ of which work solely with floating-point numbers unless otherwise noted:
.ta 3c 6c 9c
\fBabs\fR \fBacos\fR \fBasin\fR \fBatan\fR
\fBatan2\fR \fBbool\fR \fBceil\fR \fBcos\fR
-\fBcosh\fR \fBdouble\fR \fBexp\fR \fBfloor\fR
-\fBfmod\fR \fBhypot\fR \fBint\fR \fBlog\fR
-\fBlog10\fR \fBmax\fR \fBmin\fR \fBpow\fR
-\fBrand\fR \fBround\fR \fBsin\fR \fBsinh\fR
-\fBsqrt\fR \fBsrand\fR \fBtan\fR \fBtanh\fR
-\fBwide\fR
+\fBcosh\fR \fBdouble\fR \fBentier\fR \fBexp\fR
+\fBfloor\fR \fBfmod\fR \fBhypot\fR \fBint\fR
+\fBlog\fR \fBlog10\fR \fBmax\fR \fBmin\fR
+\fBpow\fR \fBrand\fR \fBround\fR \fBsin\fR
+\fBsinh\fR \fBsqrt\fR \fBsrand\fR \fBtan\fR
+\fBtanh\fR \fBwide\fR
.DE
.PP
.TP
@@ -124,7 +128,7 @@ radians. \fIx\fR and \fIy\fR cannot both be 0. If \fIx\fR is greater
than \fI0\fR, this is equivalent to \fBatan(\fIy/x\fB)\fR.
.TP
\fBbool(\fIarg\fB)\fR
-Accepts any numerical value, or any string acceptable to
+Accepts any numeric value, or any string acceptable to
\fBstring is boolean\fR, and returns the corresponding
boolean value \fB0\fR or \fB1\fR. Non-zero numbers are true.
Other numbers are false. Non-numeric strings produce boolean value in
@@ -132,7 +136,8 @@ agreement with \fBstring is true\fR and \fBstring is false\fR.
.TP
\fBceil(\fIarg\fB)\fR
Returns the smallest integral floating-point value (i.e. with a zero
-fractional part) not less than \fIarg\fR.
+fractional part) not less than \fIarg\fR. The argument may be any
+numeric value.
.TP
\fBcos(\fIarg\fB)\fR
Returns the cosine of \fIarg\fR, measured in radians.
@@ -142,16 +147,28 @@ Returns the hyperbolic cosine of \fIarg\fR. If the result would cause
an overflow, an error is returned.
.TP
\fBdouble(\fIarg\fB)\fR
+The argument may be any numeric value,
If \fIarg\fR is a floating-point value, returns \fIarg\fR, otherwise converts
-\fIarg\fR to floating-point and returns the converted value.
+\fIarg\fR to floating-point and returns the converted value. May return
+\fBInf\fR or \fB-Inf\fR when the argument is a numeric value that exceeds
+the floating-point range.
+.TP
+\fBentier(\fIarg\fB)\fR
+.VS 8.5
+The argument may be any numeric value. The integer part of \fIarg\fR
+is determined and returned. The integer range returned by this function
+is unlimited, unlike functions \fBint()\fR and \fBwide()\fR which
+truncate their range to fit in particular storage widths.
.TP
+.VE 8.5
\fBexp(\fIarg\fB)\fR
Returns the exponential of \fIarg\fR, defined as \fIe\fR**\fIarg\fR.
If the result would cause an overflow, an error is returned.
.TP
\fBfloor(\fIarg\fB)\fR
Returns the largest integral floating-point value (i.e. with a zero
-fractional part) not greater than \fIarg\fR.
+fractional part) not greater than \fIarg\fR. The argument may be
+any numeric value.
.TP
\fBfmod(\fIx, y\fB)\fR
Returns the floating-point remainder of the division of \fIx\fR by
@@ -162,11 +179,11 @@ Computes the length of the hypotenuse of a right-angled triangle
\fBsqrt(\fIx\fR*\fIx\fR+\fIy\fR*\fIy\fB)\fR.
.TP
\fBint(\fIarg\fB)\fR
-If \fIarg\fR is an integer value of the same width as the machine
-word, returns \fIarg\fR, otherwise
-converts \fIarg\fR to an integer (of the same size as a machine word,
-i.e. 32-bits on 32-bit systems, and 64-bits on 64-bit systems) by
-truncation and returns the converted value.
+The argument may be any numeric value. The integer part of \fIarg\fR
+is determined, and then the low order bits of that integer value up
+to the machine word size are returned as an integer value. For reference,
+the number of bytes in the machine word are stored in
+\fBtcl_platform(wordSize)\fR.
.TP
\fBlog(\fIarg\fB)\fR
Returns the natural logarithm of \fIarg\fR. \fIArg\fR must be a
@@ -177,10 +194,12 @@ Returns the base 10 logarithm of \fIarg\fR. \fIArg\fR must be a
positive value.
.TP
\fBmax(\fIarg\fB, \fI...\fB)\fR
-Returns the maximum value of all given numeric arguments.
+Accepts one or more numeric arguments. Returns the one argument
+with the greatest value.
.TP
\fBmin(\fIarg\fB, \fI...\fB)\fR
-Returns the minimum value of all given numeric arguments.
+Accepts one or more numeric arguments. Returns the one argument
+with the least value.
.TP
\fBpow(\fIx, y\fB)\fR
Computes the value of \fIx\fR raised to the power \fIy\fR. If \fIx\fR
@@ -207,11 +226,15 @@ Returns the hyperbolic sine of \fIarg\fR. If the result would cause
an overflow, an error is returned.
.TP
\fBsqrt(\fIarg\fB)\fR
-Returns the square root of \fIarg\fR. \fIArg\fR must be non-negative.
+The argument may be any non-negative numeric value. Returns a floating-point
+value that is the square root of \fIarg\fR. May return \fBInf\fR when the
+argument is a numeric value that exceeds the square of the maximum value of
+the floating-point range.
.TP
\fBsrand(\fIarg\fB)\fR
-The \fIarg\fR, which must be an integer, is used to reset the seed for
-the random number generator of \fBrand\fR. Returns the first random
+The \fIarg\fR, which must be an integer value acceptable to
+\fBstring is integer\fR (that is, a 32-bit integer), is used to reset the
+seed for the random number generator of \fBrand\fR. Returns the first random
number (see \fBrand()\fR) from that seed. Each interpreter has its own seed.
.TP
\fBtan(\fIarg\fB)\fR
@@ -221,8 +244,9 @@ Returns the tangent of \fIarg\fR, measured in radians.
Returns the hyperbolic tangent of \fIarg\fR.
.TP
\fBwide(\fIarg\fB)\fR
-Converts \fIarg\fR to an integer value at least 64-bits wide (by sign-extension
-if \fIarg\fR is a 32-bit number) if it is not one already.
+The argument may be any numeric value. The integer part of \fIarg\fR
+is determined, and then the low order 64 bits of that integer value
+are returned as an integer value.
.PP
In addition to these predefined functions, applications may
define additional functions by using \fBproc\fR (or any other method,
@@ -230,7 +254,7 @@ such as \fBinterp alias\fR or \fBTcl_CreateObjCommand\fR) to define
new commands in the \fBtcl::mathfunc\fR namespace. In addition, an
obsolete interface named \fBTcl_CreateMathFunc\fR() is available to
extensions that are written in C. The latter interface is not recommended
-for new implementations..
+for new implementations.
.SH "SEE ALSO"
expr(n), namespace(n)
.SH "COPYRIGHT"
diff --git a/doc/scan.n b/doc/scan.n
index 39bccdb..8dc72c9 100644
--- a/doc/scan.n
+++ b/doc/scan.n
@@ -6,7 +6,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: scan.n,v 1.16 2006/04/25 17:15:25 dgp Exp $
+'\" RCS: @(#) $Id: scan.n,v 1.17 2006/04/26 04:41:10 dgp Exp $
'\"
.so man.macros
.TH scan n 8.4 Tcl "Tcl Built-In Commands"
@@ -113,8 +113,8 @@ so the size modifer \fBll\fR is not permitted in combination
with conversion character \fBu\fR.
.TP 10
\fBi\fR
-The input substring must be an integer. The base (i.e. decimal, octal, or
-hexadecimal) is determined in the same fashion as described in
+The input substring must be an integer. The base (i.e. decimal, binary,
+octal, or hexadecimal) is determined in the same fashion as described in
\fBexpr\fR. The integer value is stored in the variable,
truncated as required by the size modifier value.
.TP 10
diff --git a/doc/string.n b/doc/string.n
index 1a1c187..8620b50 100644
--- a/doc/string.n
+++ b/doc/string.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: string.n,v 1.29 2005/05/23 17:41:00 das Exp $
+'\" RCS: @(#) $Id: string.n,v 1.30 2006/04/26 04:41:10 dgp Exp $
'\"
.so man.macros
.TH string n 8.1 Tcl "Tcl Built-In Commands"
@@ -139,9 +139,9 @@ false.
.IP \fBgraph\fR 12
Any Unicode printing character, except space.
.IP \fBinteger\fR 12
-Any of the valid forms for an ordinary integer in Tcl, with optional
-surrounding whitespace. In case of under/overflow in the value, 0 is
-returned and the \fIvarname\fR will contain \-1.
+Any of the valid string formats for a 32-bit integer value in Tcl,
+with optional surrounding whitespace. In case of under/overflow in
+the value, 0 is returned and the \fIvarname\fR will contain \-1.
.IP \fBlower\fR 12
Any Unicode lower case alphabet character.
.IP \fBprint\fR 12