diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-03-27 20:05:26 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-03-27 20:05:26 (GMT) |
commit | 9535d1ecdc9355cff86a0335a55d50a5da242457 (patch) | |
tree | 011ce18ce878a709f99580d2bde5dd2c1d0b1d1f | |
parent | 9eb32ba719b38f3e5efbb79dddcd22c42d241693 (diff) | |
download | tcl-9535d1ecdc9355cff86a0335a55d50a5da242457.zip tcl-9535d1ecdc9355cff86a0335a55d50a5da242457.tar.gz tcl-9535d1ecdc9355cff86a0335a55d50a5da242457.tar.bz2 |
Document maximum value for right argument of '**' operator.
Adapt test-cases to test for exactly one more than this maximum value.
Make sure that the maximum is the same for DIGIT_BIT > 28.
Change macro's for mp_iseven()/mp_isodd() so they don't depend on value of DIGIT_BIT any more.
-rw-r--r-- | .fossil-settings/ignore-glob | 2 | ||||
-rw-r--r-- | doc/expr.n | 3 | ||||
-rw-r--r-- | doc/mathop.n | 9 | ||||
-rw-r--r-- | generic/tclExecute.c | 6 | ||||
-rw-r--r-- | generic/tclTomMath.h | 4 | ||||
-rw-r--r-- | libtommath/astylerc | 27 | ||||
-rw-r--r-- | libtommath/tommath.h | 4 | ||||
-rw-r--r-- | tests/expr.test | 42 |
8 files changed, 66 insertions, 31 deletions
diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob index c85b488..99fd07e 100644 --- a/.fossil-settings/ignore-glob +++ b/.fossil-settings/ignore-glob @@ -24,9 +24,11 @@ libtommath/bn.ilg libtommath/bn.ind libtommath/pretty.build libtommath/tommath.src +libtommath/*.log libtommath/*.pdf libtommath/*.pl libtommath/*.sh +libtommath/doc/* libtommath/tombc/* libtommath/pre_gen/* libtommath/pics/* @@ -126,7 +126,8 @@ applied only to integers. .TP 20 \fB**\fR . -Exponentiation. Valid for any numeric operands. +Exponentiation. Valid for any numeric operands. The maximum exponent value +that Tcl can handle if the first number is an integer > 1 is 268435455. .TP 20 \fB*\0\0/\0\0%\fR . diff --git a/doc/mathop.n b/doc/mathop.n index 4c16d76..84cf308 100644 --- a/doc/mathop.n +++ b/doc/mathop.n @@ -151,10 +151,11 @@ is the same as .QW "\fB** 2 [** 3 4]\fR" . Each \fInumber\fR may be any numeric value, though the second number must not be fractional if the -first is negative. If no arguments are given, the result will be one, and if -only one argument is given, the result will be that argument. The -result will have an integral value only when all arguments are -integral values. +first is negative. The maximum exponent value that Tcl can handle if the +first number is an integer > 1 is 268435455. If no arguments are given, +the result will be one, and if only one argument is given, the result will +be that argument. The result will have an integral value only when all +arguments are integral values. .SS "COMPARISON OPERATORS" .PP The behaviors of the comparison operator commands (most of which operate diff --git a/generic/tclExecute.c b/generic/tclExecute.c index ca14a55..112924a 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -9076,7 +9076,11 @@ ExecuteExtendedBinaryMathOp( overflowExpon: Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if (big2.used > 1) { + if ((big2.used > 1) +#if DIGIT_BIT > 28 + || ((big2.used == 1) && (big2.dp[0] >= (1<<28))) +#endif + ) { mp_clear(&big2); Tcl_SetObjResult(interp, Tcl_NewStringObj( "exponent too large", -1)); diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index fbf0d35..0541ad8 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -229,8 +229,8 @@ int mp_init_size(mp_int *a, int size); /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) -#define mp_iseven(a) ((((a)->used == 0) || (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO) -#define mp_isodd(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO) +#define mp_iseven(a) (!mp_get_bit((a),0)) +#define mp_isodd(a) mp_get_bit((a),0) #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO) /* set to zero */ diff --git a/libtommath/astylerc b/libtommath/astylerc new file mode 100644 index 0000000..5d63f7a --- /dev/null +++ b/libtommath/astylerc @@ -0,0 +1,27 @@ +# Artistic Style, see http://astyle.sourceforge.net/ +# full documentation, see: http://astyle.sourceforge.net/astyle.html +# +# usage: +# astyle --options=astylerc *.[ch] + +## Bracket Style Options +style=kr + +## Tab Options +indent=spaces=3 + +## Bracket Modify Options + +## Indentation Options +min-conditional-indent=0 + +## Padding Options +pad-header +unpad-paren +align-pointer=name + +## Formatting Options +break-after-logical +max-code-length=120 +convert-tabs +mode=c diff --git a/libtommath/tommath.h b/libtommath/tommath.h index c240d80..00c8b35 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -190,8 +190,8 @@ int mp_init_size(mp_int *a, int size); /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) -#define mp_iseven(a) ((((a)->used == 0) || (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO) -#define mp_isodd(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO) +#define mp_iseven(a) (!mp_get_bit((a),0)) +#define mp_isodd(a) mp_get_bit((a),0) #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO) /* set to zero */ diff --git a/tests/expr.test b/tests/expr.test index a265ac6..6e6a358 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -1150,7 +1150,7 @@ test expr-23.54.11 {INST_EXPON: Bug 2798543} { expr {3**9 == 3**131081} } 0 test expr-23.54.12 {INST_EXPON: Bug 2798543} -body { - expr {3**9 == 3**268435465} + expr {3**268435456} } -returnCodes error -result {exponent too large} test expr-23.54.13 {INST_EXPON: Bug 2798543} { expr {(-3)**9 == (-3)**65545} @@ -1165,7 +1165,7 @@ test expr-23.55.2 {INST_EXPON: Bug 2798543} { expr {4**9 == 4**131081} } 0 test expr-23.55.3 {INST_EXPON: Bug 2798543} -body { - expr {4**9 == 4**268435465} + expr {4**268435456} } -returnCodes error -result {exponent too large} test expr-23.55.4 {INST_EXPON: Bug 2798543} { expr {(-4)**9 == (-4)**65545} @@ -1180,7 +1180,7 @@ test expr-23.56.2 {INST_EXPON: Bug 2798543} { expr {5**9 == 5**131081} } 0 test expr-23.56.3 {INST_EXPON: Bug 2798543} -body { - expr {5**9 == 5**268435465} + expr {5**268435456} } -returnCodes error -result {exponent too large} test expr-23.56.4 {INST_EXPON: Bug 2798543} { expr {(-5)**9 == (-5)**65545} @@ -1195,7 +1195,7 @@ test expr-23.57.2 {INST_EXPON: Bug 2798543} { expr {6**9 == 6**131081} } 0 test expr-23.57.3 {INST_EXPON: Bug 2798543} -body { - expr {6**9 == 6**268435465} + expr {6**268435456} } -returnCodes error -result {exponent too large} test expr-23.57.4 {INST_EXPON: Bug 2798543} { expr {(-6)**9 == (-6)**65545} @@ -1210,7 +1210,7 @@ test expr-23.58.2 {INST_EXPON: Bug 2798543} { expr {7**9 == 7**131081} } 0 test expr-23.58.3 {INST_EXPON: Bug 2798543} -body { - expr {7**9 == 7**268435465} + expr {7**268435456} } -returnCodes error -result {exponent too large} test expr-23.58.4 {INST_EXPON: Bug 2798543} { expr {(-7)**9 == (-7)**65545} @@ -1225,7 +1225,7 @@ test expr-23.59.2 {INST_EXPON: Bug 2798543} { expr {8**9 == 8**131081} } 0 test expr-23.59.3 {INST_EXPON: Bug 2798543} -body { - expr {8**9 == 8**268435465} + expr {8**268435456} } -returnCodes error -result {exponent too large} test expr-23.59.4 {INST_EXPON: Bug 2798543} { expr {(-8)**9 == (-8)**65545} @@ -1237,7 +1237,7 @@ test expr-23.60.1 {INST_EXPON: Bug 2798543} { expr {9**9 == 9**131081} } 0 test expr-23.60.2 {INST_EXPON: Bug 2798543} -body { - expr {9**9 == 9**268435465} + expr {9**268435456} } -returnCodes error -result {exponent too large} test expr-23.60.3 {INST_EXPON: Bug 2798543} { expr {(-9)**9 == (-9)**65545} @@ -1249,7 +1249,7 @@ test expr-23.61.1 {INST_EXPON: Bug 2798543} { expr {10**9 == 10**131081} } 0 test expr-23.61.2 {INST_EXPON: Bug 2798543} -body { - expr {10**9 == 10**268435465} + expr {10**268435456} } -returnCodes error -result {exponent too large} test expr-23.61.3 {INST_EXPON: Bug 2798543} { expr {(-10)**9 == (-10)**65545} @@ -1261,7 +1261,7 @@ test expr-23.62.1 {INST_EXPON: Bug 2798543} { expr {11**9 == 11**131081} } 0 test expr-23.62.2 {INST_EXPON: Bug 2798543} -body { - expr {11**9 == 11**268435465} + expr {11**268435456} } -returnCodes error -result {exponent too large} test expr-23.62.3 {INST_EXPON: Bug 2798543} { expr {(-11)**9 == (-11)**65545} @@ -1276,7 +1276,7 @@ test expr-23.63.2 {INST_EXPON: Bug 2798543} { expr {3**20 == 3**131092} } 0 test expr-23.63.3 {INST_EXPON: Bug 2798543} -body { - expr {3**20 == 3**268435476} + expr {3**268435456} } -returnCodes error -result {exponent too large} test expr-23.63.4 {INST_EXPON: Bug 2798543} { expr {(-3)**20 == (-3)**65556} @@ -1291,7 +1291,7 @@ test expr-23.64.2 {INST_EXPON: Bug 2798543} { expr {4**17 == 4**131089} } 0 test expr-23.64.3 {INST_EXPON: Bug 2798543} -body { - expr {4**17 == 4**268435473} + expr {4**268435456} } -returnCodes error -result {exponent too large} test expr-23.64.4 {INST_EXPON: Bug 2798543} { expr {(-4)**17 == (-4)**65553} @@ -1306,7 +1306,7 @@ test expr-23.65.2 {INST_EXPON: Bug 2798543} { expr {5**17 == 5**131089} } 0 test expr-23.65.3 {INST_EXPON: Bug 2798543} -body { - expr {5**17 == 5**268435473} + expr {5**268435456} } -returnCodes error -result {exponent too large} test expr-23.65.4 {INST_EXPON: Bug 2798543} { expr {(-5)**17 == (-5)**65553} @@ -1321,7 +1321,7 @@ test expr-23.66.2 {INST_EXPON: Bug 2798543} { expr {6**17 == 6**131089} } 0 test expr-23.66.3 {INST_EXPON: Bug 2798543} -body { - expr {6**17 == 6**268435473} + expr {6**268435456} } -returnCodes error -result {exponent too large} test expr-23.66.4 {INST_EXPON: Bug 2798543} { expr {(-6)**17 == (-6)**65553} @@ -1336,7 +1336,7 @@ test expr-23.67.2 {INST_EXPON: Bug 2798543} { expr {7**17 == 7**131089} } 0 test expr-23.67.3 {INST_EXPON: Bug 2798543} -body { - expr {7**17 == 7**268435473} + expr {7**268435456} } -returnCodes error -result {exponent too large} test expr-23.67.4 {INST_EXPON: Bug 2798543} { expr {(-7)**17 == (-7)**65553} @@ -1351,7 +1351,7 @@ test expr-23.68.2 {INST_EXPON: Bug 2798543} { expr {8**17 == 8**131089} } 0 test expr-23.68.3 {INST_EXPON: Bug 2798543} -body { - expr {8**17 == 8**268435473} + expr {8**268435456} } -returnCodes error -result {exponent too large} test expr-23.68.4 {INST_EXPON: Bug 2798543} { expr {(-8)**17 == (-8)**65553} @@ -1366,7 +1366,7 @@ test expr-23.69.2 {INST_EXPON: Bug 2798543} { expr {9**17 == 9**131089} } 0 test expr-23.69.3 {INST_EXPON: Bug 2798543} -body { - expr {9**17 == 9**268435473} + expr {9**268435456} } -returnCodes error -result {exponent too large} test expr-23.69.4 {INST_EXPON: Bug 2798543} { expr {(-9)**17 == (-9)**65553} @@ -1381,7 +1381,7 @@ test expr-23.70.2 {INST_EXPON: Bug 2798543} { expr {10**17 == 10**131089} } 0 test expr-23.70.3 {INST_EXPON: Bug 2798543} -body { - expr {10**17 == 10**268435473} + expr {10**268435456} } -returnCodes error -result {exponent too large} test expr-23.70.4 {INST_EXPON: Bug 2798543} { expr {(-10)**17 == (-10)**65553} @@ -1396,7 +1396,7 @@ test expr-23.71.2 {INST_EXPON: Bug 2798543} { expr {11**17 == 11**131089} } 0 test expr-23.71.3 {INST_EXPON: Bug 2798543} -body { - expr {11**17 == 11**268435473} + expr {11**268435456} } -returnCodes error -result {exponent too large} test expr-23.71.4 {INST_EXPON: Bug 2798543} { expr {(-11)**17 == (-11)**65553} @@ -1408,7 +1408,7 @@ test expr-23.72.1 {INST_EXPON: Bug 2798543} { expr {12**17 == 12**131089} } 0 test expr-23.72.2 {INST_EXPON: Bug 2798543} -body { - expr {12**17 == 12**268435473} + expr {12**268435456} } -returnCodes error -result {exponent too large} test expr-23.72.3 {INST_EXPON: Bug 2798543} { expr {(-12)**17 == (-12)**65553} @@ -1420,7 +1420,7 @@ test expr-23.73.1 {INST_EXPON: Bug 2798543} { expr {13**17 == 13**131089} } 0 test expr-23.73.2 {INST_EXPON: Bug 2798543} -body { - expr {13**17 == 13**268435473} + expr {13**268435456} } -returnCodes error -result {exponent too large} test expr-23.73.3 {INST_EXPON: Bug 2798543} { expr {(-13)**17 == (-13)**65553} @@ -1432,7 +1432,7 @@ test expr-23.74.1 {INST_EXPON: Bug 2798543} { expr {14**17 == 14**131089} } 0 test expr-23.74.2 {INST_EXPON: Bug 2798543} -body { - expr {14**17 == 14**268435473} + expr {14**268435456} } -returnCodes error -result {exponent too large} test expr-23.74.3 {INST_EXPON: Bug 2798543} { expr {(-14)**17 == (-14)**65553} |