summaryrefslogtreecommitdiffstats
path: root/tests/expr.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/expr.test')
-rw-r--r--tests/expr.test1567
1 files changed, 1216 insertions, 351 deletions
diff --git a/tests/expr.test b/tests/expr.test
index 50159c0..6ad7208 100644
--- a/tests/expr.test
+++ b/tests/expr.test
@@ -9,16 +9,17 @@
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-#
-# RCS: @(#) $Id: expr.test,v 1.44 2005/08/29 17:54:22 kennykb Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2.1
namespace import -force ::tcltest::*
}
+::tcltest::loadTestedCommands
+catch [list package require -exact Tcltest [info patchlevel]]
+
testConstraint testmathfunctions [expr {
- ([catch {expr T1()} msg] != 1) || ($msg ne {unknown math function "T1"})
+ ([catch {expr T1()} msg] != 1) || ($msg ne {invalid command name "tcl::mathfunc::T1"})
}]
# Determine if "long int" type is a 32 bit number and if the wide
@@ -26,7 +27,8 @@ testConstraint testmathfunctions [expr {
testConstraint longIs32bit [expr {int(0x80000000) < 0}]
testConstraint longIs64bit [expr {int(0x8000000000000000) < 0}]
-testConstraint wideIs64bit [expr {(0x80000000 > 0) && (0x8000000000000000 < 0)}]
+testConstraint wideIs64bit \
+ [expr {(wide(0x80000000) > 0) && (wide(0x8000000000000000) < 0)}]
# Big test for correct ordering of data in [expr]
@@ -54,6 +56,8 @@ proc testIEEE {} {
ieeeValues(+Infinity)
binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \
ieeeValues(NaN)
+ binary scan \x00\x00\x00\x00\x00\x00\xf8\xff d \
+ ieeeValues(-NaN)
set ieeeValues(littleEndian) 1
return 1
}
@@ -76,6 +80,8 @@ proc testIEEE {} {
ieeeValues(+Infinity)
binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \
ieeeValues(NaN)
+ binary scan \xff\xf8\x00\x00\x00\x00\x00\x00 d \
+ ieeeValues(-NaN)
set ieeeValues(littleEndian) 0
return 1
}
@@ -198,33 +204,28 @@ test expr-1.15 {TclCompileExprCmd: second level of substitutions in expr with co
test expr-2.1 {TclCompileExpr: are builtin functions registered?} {
expr double(5*[llength "6 2"])
} 10.0
-test expr-2.2 {TclCompileExpr: error in expr} {
- catch {expr 2***3} msg
- set msg
-} {syntax error in expression "2***3": unexpected operator *}
-test expr-2.3 {TclCompileExpr: junk after legal expr} {
- catch {expr 7*[llength "a b"]foo} msg
- set msg
-} {syntax error in expression "7*2foo": extra tokens at end of expression}
+test expr-2.2 {TclCompileExpr: error in expr} -body {
+ expr 2***3
+} -returnCodes error -match glob -result *
+test expr-2.3 {TclCompileExpr: junk after legal expr} -body {
+ expr 7*[llength "a b"]foo
+} -returnCodes error -match glob -result *
test expr-2.4 {TclCompileExpr: numeric expr string rep == formatted int rep} {
expr {0001}
} 1
test expr-3.1 {CompileCondExpr: just lor expr} {expr 3||0} 1
test expr-3.2 {CompileCondExpr: error in lor expr} -body {
- catch {expr x||3} msg
- set msg
-} -match glob -result {syntax error in expression "x||3": * preceding $*}
+ expr x||3
+} -returnCodes error -match glob -result *
test expr-3.3 {CompileCondExpr: test true arm} {expr 3>2?44:66} 44
-test expr-3.4 {CompileCondExpr: error compiling true arm} {
- catch {expr 3>2?2***3:66} msg
- set msg
-} {syntax error in expression "3>2?2***3:66": unexpected operator *}
+test expr-3.4 {CompileCondExpr: error compiling true arm} -body {
+ expr 3>2?2***3:66
+} -returnCodes error -match glob -result *
test expr-3.5 {CompileCondExpr: test false arm} {expr 2>3?44:66} 66
-test expr-3.6 {CompileCondExpr: error compiling false arm} {
- catch {expr 2>3?44:2***3} msg
- set msg
-} {syntax error in expression "2>3?44:2***3": unexpected operator *}
+test expr-3.6 {CompileCondExpr: error compiling false arm} -body {
+ expr 2>3?44:2***3
+} -returnCodes error -match glob -result *
test expr-3.7 {CompileCondExpr: long arms & nested cond exprs} {
hello_world
} {Hello world}
@@ -235,20 +236,17 @@ test expr-3.8 {CompileCondExpr: long arms & nested cond exprs} unix {
test expr-4.1 {CompileLorExpr: just land expr} {expr 1.3&&3.3} 1
test expr-4.2 {CompileLorExpr: error in land expr} -body {
- catch {expr x&&3} msg
- set msg
-} -match glob -result {syntax error in expression "x&&3": *preceding $*}
+ expr x&&3
+} -returnCodes error -match glob -result *
test expr-4.3 {CompileLorExpr: simple lor exprs} {expr 0||1.0} 1
test expr-4.4 {CompileLorExpr: simple lor exprs} {expr 3.0||0.0} 1
test expr-4.5 {CompileLorExpr: simple lor exprs} {expr 0||0||1} 1
-test expr-4.6 {CompileLorExpr: error compiling lor arm} {
- catch {expr 2***3||4.0} msg
- set msg
-} {syntax error in expression "2***3||4.0": unexpected operator *}
-test expr-4.7 {CompileLorExpr: error compiling lor arm} {
- catch {expr 1.3||2***3} msg
- set msg
-} {syntax error in expression "1.3||2***3": unexpected operator *}
+test expr-4.6 {CompileLorExpr: error compiling lor arm} -body {
+ expr 2***3||4.0
+} -returnCodes error -match glob -result *
+test expr-4.7 {CompileLorExpr: error compiling lor arm} -body {
+ expr 1.3||2***3
+} -returnCodes error -match glob -result *
test expr-4.8 {CompileLorExpr: error compiling lor arms} {
list [catch {expr {"a"||"b"}} msg] $msg
} {1 {expected boolean value but got "a"}}
@@ -269,21 +267,18 @@ test expr-4.12 {CompileLorExpr: error compiling land arms} {
test expr-5.1 {CompileLandExpr: just bitor expr} {expr 7|0x13} 23
test expr-5.2 {CompileLandExpr: error in bitor expr} -body {
- catch {expr x|3} msg
- set msg
-} -match glob -result {syntax error in expression "x|3": * preceding $*}
+ expr x|3
+} -returnCodes error -match glob -result *
test expr-5.3 {CompileLandExpr: simple land exprs} {expr 0&&1.0} 0
test expr-5.4 {CompileLandExpr: simple land exprs} {expr 0&&0} 0
test expr-5.5 {CompileLandExpr: simple land exprs} {expr 3.0&&1.2} 1
test expr-5.6 {CompileLandExpr: simple land exprs} {expr 1&&1&&2} 1
-test expr-5.7 {CompileLandExpr: error compiling land arm} {
- catch {expr 2***3&&4.0} msg
- set msg
-} {syntax error in expression "2***3&&4.0": unexpected operator *}
-test expr-5.8 {CompileLandExpr: error compiling land arm} {
- catch {expr 1.3&&2***3} msg
- set msg
-} {syntax error in expression "1.3&&2***3": unexpected operator *}
+test expr-5.7 {CompileLandExpr: error compiling land arm} -body {
+ expr 2***3&&4.0
+} -returnCodes error -match glob -result *
+test expr-5.8 {CompileLandExpr: error compiling land arm} -body {
+ expr 1.3&&2***3
+} -returnCodes error -match glob -result *
test expr-5.9 {CompileLandExpr: error compiling land arm} {
list [catch {expr {"a"&&"b"}} msg] $msg
} {1 {expected boolean value but got "a"}}
@@ -295,21 +290,18 @@ test expr-5.10 {CompileLandExpr: long land arms} {
test expr-6.1 {CompileBitXorExpr: just bitand expr} {expr 7&0x13} 3
test expr-6.2 {CompileBitXorExpr: error in bitand expr} -body {
- catch {expr x|3} msg
- set msg
-} -match glob -result {syntax error in expression "x|3": * preceding $*}
+ expr x|3
+} -returnCodes error -match glob -result *
test expr-6.3 {CompileBitXorExpr: simple bitxor exprs} {expr 7^0x13} 20
test expr-6.4 {CompileBitXorExpr: simple bitxor exprs} {expr 3^0x10} 19
test expr-6.5 {CompileBitXorExpr: simple bitxor exprs} {expr 0^7} 7
test expr-6.6 {CompileBitXorExpr: simple bitxor exprs} {expr -1^7} -8
-test expr-6.7 {CompileBitXorExpr: error compiling bitxor arm} {
- catch {expr 2***3|6} msg
- set msg
-} {syntax error in expression "2***3|6": unexpected operator *}
+test expr-6.7 {CompileBitXorExpr: error compiling bitxor arm} -body {
+ expr 2***3|6
+} -returnCodes error -match glob -result *
test expr-6.8 {CompileBitXorExpr: error compiling bitxor arm} -body {
- catch {expr 2^x} msg
- set msg
-} -match glob -result {syntax error in expression "2^x": * preceding $**}
+ expr 2^x
+} -returnCodes error -match glob -result *
test expr-6.9 {CompileBitXorExpr: runtime error in bitxor arm} {
list [catch {expr {24.0^3}} msg] $msg
} {1 {can't use floating-point value as operand of "^"}}
@@ -322,21 +314,18 @@ test expr-7.2 {CompileBitAndExpr: just equality expr} {expr 2.0==2} 1
test expr-7.3 {CompileBitAndExpr: just equality expr} {expr 3.2!=2.2} 1
test expr-7.4 {CompileBitAndExpr: just equality expr} {expr {"abc" == "abd"}} 0
test expr-7.5 {CompileBitAndExpr: error in equality expr} -body {
- catch {expr x==3} msg
- set msg
-} -match glob -result {syntax error in expression "x==3": * preceding $*}
+ expr x==3
+} -returnCodes error -match glob -result *
test expr-7.6 {CompileBitAndExpr: simple bitand exprs} {expr 7&0x13} 3
test expr-7.7 {CompileBitAndExpr: simple bitand exprs} {expr 0xf2&0x53} 82
test expr-7.8 {CompileBitAndExpr: simple bitand exprs} {expr 3&6} 2
test expr-7.9 {CompileBitAndExpr: simple bitand exprs} {expr -1&-7} -7
-test expr-7.10 {CompileBitAndExpr: error compiling bitand arm} {
- catch {expr 2***3&6} msg
- set msg
-} {syntax error in expression "2***3&6": unexpected operator *}
+test expr-7.10 {CompileBitAndExpr: error compiling bitand arm} -body {
+ expr 2***3&6
+} -returnCodes error -match glob -result *
test expr-7.11 {CompileBitAndExpr: error compiling bitand arm} -body {
- catch {expr 2&x} msg
- set msg
-} -match glob -result {syntax error in expression "2&x": * preceding $*}
+ expr 2&x
+} -returnCodes error -match glob -result *
test expr-7.12 {CompileBitAndExpr: runtime error in bitand arm} {
list [catch {expr {24.0&3}} msg] $msg
} {1 {can't use floating-point value as operand of "&"}}
@@ -346,32 +335,28 @@ test expr-7.13 {CompileBitAndExpr: runtime error in bitand arm} {
test expr-7.14 {CompileBitAndExpr: equality expr} {expr 3eq2} 0
test expr-7.18 {CompileBitAndExpr: equality expr} {expr {"abc" eq "abd"}} 0
test expr-7.20 {CompileBitAndExpr: error in equality expr} -body {
- catch {expr xne3} msg
- set msg
-} -match glob -result {syntax error in expression "xne3": * preceding $*}
+ expr xne3
+} -returnCodes error -match glob -result *
test expr-8.1 {CompileEqualityExpr: just relational expr} {expr 3>=2} 1
test expr-8.2 {CompileEqualityExpr: just relational expr} {expr 2<=2.1} 1
test expr-8.3 {CompileEqualityExpr: just relational expr} {expr 3.2>"2.2"} 1
test expr-8.4 {CompileEqualityExpr: just relational expr} {expr {"0y"<"0x12"}} 0
test expr-8.5 {CompileEqualityExpr: error in relational expr} -body {
- catch {expr x>3} msg
- set msg
-} -match glob -result {syntax error in expression "x>3": * preceding $*}
+ expr x>3
+} -returnCodes error -match glob -result *
test expr-8.6 {CompileEqualityExpr: simple equality exprs} {expr 7==0x13} 0
test expr-8.7 {CompileEqualityExpr: simple equality exprs} {expr -0xf2!=0x53} 1
test expr-8.8 {CompileEqualityExpr: simple equality exprs} {expr {"12398712938788234-1298379" != ""}} 1
test expr-8.9 {CompileEqualityExpr: simple equality exprs} {expr -1!="abc"} 1
-test expr-8.10 {CompileEqualityExpr: error compiling equality arm} {
- catch {expr 2***3==6} msg
- set msg
-} {syntax error in expression "2***3==6": unexpected operator *}
+test expr-8.10 {CompileEqualityExpr: error compiling equality arm} -body {
+ expr 2***3==6
+} -returnCodes error -match glob -result *
test expr-8.11 {CompileEqualityExpr: error compiling equality arm} -body {
- catch {expr 2!=x} msg
- set msg
-} -match glob -result {syntax error in expression "2!=x": * preceding $*}
+ expr 2!=x
+} -returnCodes error -match glob -result *
test expr-8.12 {CompileBitAndExpr: equality expr} {expr {"a"eq"a"}} 1
-test expr-8.13 {CompileBitAndExpr: equality expr} {expr {"\374" eq "ü"}} 1
+test expr-8.13 {CompileBitAndExpr: equality expr} {expr {"\374" eq [set s \u00fc]}} 1
test expr-8.14 {CompileBitAndExpr: equality expr} {expr 3eq2} 0
test expr-8.15 {CompileBitAndExpr: equality expr} {expr 2.0eq2} 0
test expr-8.16 {CompileBitAndExpr: equality expr} {expr 3.2ne2.2} 1
@@ -379,22 +364,18 @@ test expr-8.17 {CompileBitAndExpr: equality expr} {expr 01eq1} 0
test expr-8.18 {CompileBitAndExpr: equality expr} {expr {"abc" eq "abd"}} 0
test expr-8.19 {CompileBitAndExpr: equality expr} {expr {"abc" ne "abd"}} 1
test expr-8.20 {CompileBitAndExpr: error in equality expr} -body {
- catch {expr x ne3} msg
- set msg
-} -match glob -result {syntax error in expression "x ne3": * preceding $*}
+ expr x ne3
+} -returnCodes error -match glob -result *
test expr-8.21 {CompileBitAndExpr: error in equality expr} -body {
# These should be ""ed to avoid the error
- catch {expr a eq b} msg
- set msg
-} -match glob -result {syntax error in expression "a eq b": * preceding $*}
-test expr-8.22 {CompileBitAndExpr: error in equality expr} {
- catch {expr {false eqfalse}} msg
- set msg
-} {syntax error in expression "false eqfalse": extra tokens at end of expression}
-test expr-8.23 {CompileBitAndExpr: error in equality expr} {
- catch {expr {false nefalse}} msg
- set msg
-} {syntax error in expression "false nefalse": extra tokens at end of expression}
+ expr a eq b
+} -returnCodes error -match glob -result *
+test expr-8.22 {CompileBitAndExpr: error in equality expr} -body {
+ expr {false eqfalse}
+} -returnCodes error -match glob -result *
+test expr-8.23 {CompileBitAndExpr: error in equality expr} -body {
+ expr {false nefalse}
+} -returnCodes error -match glob -result *
test expr-8.24 {CompileEqualityExpr: simple equality exprs} {
set x 12398712938788234
expr {$x == 100}
@@ -420,65 +401,59 @@ test expr-8.29 {CompileEqualityExpr: just relational expr} {
test expr-8.30 {CompileEqualityExpr: simple equality exprs} {
expr {"fake" != "bob"}
} 1
-test expr-8.31 {expr edge cases} {
- list [catch {expr {1e}} err] $err
-} {1 {syntax error in expression "1e": extra tokens at end of expression}}
-test expr-8.32 {expr edge cases} {
- list [catch {expr {1E}} err] $err
-} {1 {syntax error in expression "1E": extra tokens at end of expression}}
-test expr-8.33 {expr edge cases} {
- list [catch {expr {1e+}} err] $err
-} {1 {syntax error in expression "1e+": extra tokens at end of expression}}
-test expr-8.34 {expr edge cases} {
- list [catch {expr {1E+}} err] $err
-} {1 {syntax error in expression "1E+": extra tokens at end of expression}}
-test expr-8.35 {expr edge cases} {
- list [catch {expr {1ea}} err] $err
-} {1 {syntax error in expression "1ea": extra tokens at end of expression}}
+test expr-8.31 {expr edge cases} -body {
+ expr {1e}
+} -returnCodes error -match glob -result *
+test expr-8.32 {expr edge cases} -body {
+ expr {1E}
+} -returnCodes error -match glob -result *
+test expr-8.33 {expr edge cases} -body {
+ expr {1e+}
+} -returnCodes error -match glob -result *
+test expr-8.34 {expr edge cases} -body {
+ expr {1E+}
+} -returnCodes error -match glob -result *
+test expr-8.35 {expr edge cases} -body {
+ expr {1ea}
+} -returnCodes error -match glob -result *
test expr-9.1 {CompileRelationalExpr: just shift expr} {expr 3<<2} 12
test expr-9.2 {CompileRelationalExpr: just shift expr} {expr 0xff>>2} 63
test expr-9.3 {CompileRelationalExpr: just shift expr} {expr -1>>2} -1
test expr-9.4 {CompileRelationalExpr: just shift expr} {expr {1<<3}} 8
test expr-9.5a {CompileRelationalExpr: shift expr producing LONG_MIN} longIs64bit {
- expr {1<<63}
+ expr {int(1<<63)}
} -9223372036854775808
test expr-9.5b {CompileRelationalExpr: shift expr producing LONG_MIN} longIs32bit {
- expr {1<<31}
+ expr {int(1<<31)}
} -2147483648
test expr-9.6 {CompileRelationalExpr: error in shift expr} -body {
- catch {expr x>>3} msg
- set msg
-} -match glob -result {syntax error in expression "x>>3": * preceding $*}
+ expr x>>3
+} -returnCodes error -match glob -result *
test expr-9.7 {CompileRelationalExpr: simple relational exprs} {expr 0xff>=+0x3} 1
test expr-9.8 {CompileRelationalExpr: simple relational exprs} {expr -0xf2<0x3} 1
-test expr-9.9 {CompileRelationalExpr: error compiling relational arm} {
- catch {expr 2***3>6} msg
- set msg
-} {syntax error in expression "2***3>6": unexpected operator *}
+test expr-9.9 {CompileRelationalExpr: error compiling relational arm} -body {
+ expr 2***3>6
+} -returnCodes error -match glob -result *
test expr-9.10 {CompileRelationalExpr: error compiling relational arm} -body {
- catch {expr 2<x} msg
- set msg
-} -match glob -result {syntax error in expression "2<x": * preceding $*}
+ expr 2<x
+} -returnCodes error -match glob -result *
test expr-10.1 {CompileShiftExpr: just add expr} {expr 4+-2} 2
test expr-10.2 {CompileShiftExpr: just add expr} {expr 0xff-2} 253
test expr-10.3 {CompileShiftExpr: just add expr} {expr -1--2} 1
-test expr-10.4 {CompileShiftExpr: just add expr} {expr 1-0123} -82
+test expr-10.4 {CompileShiftExpr: just add expr} {expr 1-0o123} -82
test expr-10.5 {CompileShiftExpr: error in add expr} -body {
- catch {expr x+3} msg
- set msg
-} -match glob -result {syntax error in expression "x+3": * preceding $*}
+ expr x+3
+} -returnCodes error -match glob -result *
test expr-10.6 {CompileShiftExpr: simple shift exprs} {expr 0xff>>0x3} 31
test expr-10.7 {CompileShiftExpr: simple shift exprs} {expr -0xf2<<0x3} -1936
-test expr-10.8 {CompileShiftExpr: error compiling shift arm} {
- catch {expr 2***3>>6} msg
- set msg
-} {syntax error in expression "2***3>>6": unexpected operator *}
+test expr-10.8 {CompileShiftExpr: error compiling shift arm} -body {
+ expr 2***3>>6
+} -returnCodes error -match glob -result *
test expr-10.9 {CompileShiftExpr: error compiling shift arm} -body {
- catch {expr 2<<x} msg
- set msg
-} -match glob -result {syntax error in expression "2<<x": * preceding $*}
+ expr 2<<x
+} -returnCodes error -match glob -result *
test expr-10.10 {CompileShiftExpr: runtime error} {
list [catch {expr {24.0>>43}} msg] $msg
} {1 {can't use floating-point value as operand of ">>"}}
@@ -489,21 +464,18 @@ test expr-10.11 {CompileShiftExpr: runtime error} {
test expr-11.1 {CompileAddExpr: just multiply expr} {expr 4*-2} -8
test expr-11.2 {CompileAddExpr: just multiply expr} {expr 0xff%2} 1
test expr-11.3 {CompileAddExpr: just multiply expr} {expr -1/2} -1
-test expr-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0123} 6
+test expr-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0o123} 6
test expr-11.5 {CompileAddExpr: error in multiply expr} -body {
- catch {expr x*3} msg
- set msg
-} -match glob -result {syntax error in expression "x*3": * preceding $*}
+ expr x*3
+} -returnCodes error -match glob -result *
test expr-11.6 {CompileAddExpr: simple add exprs} {expr 0xff++0x3} 258
test expr-11.7 {CompileAddExpr: simple add exprs} {expr -0xf2--0x3} -239
-test expr-11.8 {CompileAddExpr: error compiling add arm} {
- catch {expr 2***3+6} msg
- set msg
-} {syntax error in expression "2***3+6": unexpected operator *}
+test expr-11.8 {CompileAddExpr: error compiling add arm} -body {
+ expr 2***3+6
+} -returnCodes error -match glob -result *
test expr-11.9 {CompileAddExpr: error compiling add arm} -body {
- catch {expr 2-x} msg
- set msg
-} -match glob -result {syntax error in expression "2-x": * preceding $*}
+ expr 2-x
+} -returnCodes error -match glob -result *
test expr-11.10 {CompileAddExpr: runtime error} {
list [catch {expr {24.0+"xx"}} msg] $msg
} {1 {can't use non-numeric string as operand of "+"}}
@@ -525,19 +497,16 @@ test expr-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5
test expr-12.3 {CompileMultiplyExpr: just unary expr} {expr !27} 0
test expr-12.4 {CompileMultiplyExpr: just unary expr} {expr ~0xff00ff} -16711936
test expr-12.5 {CompileMultiplyExpr: error in unary expr} -body {
- catch {expr ~x} msg
- set msg
-} -match glob -result {syntax error in expression "~x": * preceding $*}
+ expr ~x
+} -returnCodes error -match glob -result *
test expr-12.6 {CompileMultiplyExpr: simple multiply exprs} {expr 0xff*0x3} 765
test expr-12.7 {CompileMultiplyExpr: simple multiply exprs} {expr -0xf2%-0x3} -2
-test expr-12.8 {CompileMultiplyExpr: error compiling multiply arm} {
- catch {expr 2*3%%6} msg
- set msg
-} {syntax error in expression "2*3%%6": unexpected operator %}
+test expr-12.8 {CompileMultiplyExpr: error compiling multiply arm} -body {
+ expr 2*3%%6
+} -returnCodes error -match glob -result *
test expr-12.9 {CompileMultiplyExpr: error compiling multiply arm} -body {
- catch {expr 2*x} msg
- set msg
-} -match glob -result {syntax error in expression "2*x": * preceding $*}
+ expr 2*x
+} -returnCodes error -match glob -result *
test expr-12.10 {CompileMultiplyExpr: runtime error} {
list [catch {expr {24.0*"xx"}} msg] $msg
} {1 {can't use non-numeric string as operand of "*"}}
@@ -546,20 +515,18 @@ test expr-12.11 {CompileMultiplyExpr: runtime error} {
} {1 {can't use non-numeric string as operand of "/"}}
test expr-13.1 {CompileUnaryExpr: unary exprs} {expr -0xff} -255
-test expr-13.2 {CompileUnaryExpr: unary exprs} {expr +000123} 83
+test expr-13.2 {CompileUnaryExpr: unary exprs} {expr +0o00123} 83
test expr-13.3 {CompileUnaryExpr: unary exprs} {expr +--++36} 36
test expr-13.4 {CompileUnaryExpr: unary exprs} {expr !2} 0
test expr-13.5 {CompileUnaryExpr: unary exprs} {expr +--+-62.0} -62.0
test expr-13.6 {CompileUnaryExpr: unary exprs} {expr !0.0} 1
test expr-13.7 {CompileUnaryExpr: unary exprs} {expr !0xef} 0
test expr-13.8 {CompileUnaryExpr: error compiling unary expr} -body {
- catch {expr ~x} msg
- set msg
-} -match glob -result {syntax error in expression "~x": * preceding $*}
-test expr-13.9 {CompileUnaryExpr: error compiling unary expr} {
- catch {expr !1.x} msg
- set msg
-} {syntax error in expression "!1.x": extra tokens at end of expression}
+ expr ~x
+} -returnCodes error -match glob -result *
+test expr-13.9 {CompileUnaryExpr: error compiling unary expr} -body {
+ expr !1.x
+} -returnCodes error -match glob -result *
test expr-13.10 {CompileUnaryExpr: runtime error} {
list [catch {expr {~"xx"}} msg] $msg
} {1 {can't use non-numeric string as operand of "~"}}
@@ -587,7 +554,7 @@ test expr-13.17 {CompileUnaryExpr: negating non-numeric boolean literals} {
test expr-14.1 {CompilePrimaryExpr: literal primary} {expr 1} 1
test expr-14.2 {CompilePrimaryExpr: literal primary} {expr 123} 123
test expr-14.3 {CompilePrimaryExpr: literal primary} {expr 0xff} 255
-test expr-14.4 {CompilePrimaryExpr: literal primary} {expr 00010} 8
+test expr-14.4 {CompilePrimaryExpr: literal primary} {expr 0o0010} 8
test expr-14.5 {CompilePrimaryExpr: literal primary} {expr 62.0} 62.0
test expr-14.6 {CompilePrimaryExpr: literal primary} {
expr 3.1400000
@@ -625,14 +592,11 @@ test expr-14.15 {CompilePrimaryExpr: var reference primary} {
set msg
} 123.2
test expr-14.16 {CompilePrimaryExpr: error compiling var reference primary} -body {
- catch {expr {$a(foo}} msg
- set errorInfo
-} -match glob -result {missing )
- while *ing
-"expr {$a(foo}"}
-test expr-14.17 {CompilePrimaryExpr: string primary that looks like var ref} {
+ expr {$a(foo}
+} -returnCodes error -match glob -result *
+test expr-14.17 {CompilePrimaryExpr: string primary that looks like var ref} -body {
expr $
-} $
+} -returnCodes error -match glob -result *
test expr-14.18 {CompilePrimaryExpr: quoted string primary} {
expr "21"
} 21
@@ -655,16 +619,13 @@ test expr-14.22 {CompilePrimaryExpr: subcommand primary} {
} 123
test expr-14.23 {CompilePrimaryExpr: error in subcommand primary} -body {
catch {expr {[set]}} msg
- set errorInfo
+ set ::errorInfo
} -match glob -result {wrong # args: should be "set varName ?newValue?"
while *ing
"set"*}
test expr-14.24 {CompilePrimaryExpr: error in subcommand primary} -body {
- catch {expr {[set i}} msg
- set errorInfo
-} -match glob -result {missing close-bracket
- while *ing
-"expr {\[set i}"}
+ expr {[set i}
+} -returnCodes error -match glob -result *
test expr-14.25 {CompilePrimaryExpr: math function primary} {
format %.6g [expr exp(1.0)]
} 2.71828
@@ -672,73 +633,58 @@ test expr-14.26 {CompilePrimaryExpr: math function primary} {
format %.6g [expr pow(2.0+0.1,3.0+0.1)]
} 9.97424
test expr-14.27 {CompilePrimaryExpr: error in math function primary} -body {
- catch {expr sinh::(2.0)} msg
- set errorInfo
-} -match glob -result {syntax error in expression "sinh::(2.0)": * function arguments*
- while *ing
-"expr sinh::(2.0)"}
+ expr sinh::(2.0)
+} -returnCodes error -match glob -result *
test expr-14.28 {CompilePrimaryExpr: subexpression primary} {
expr 2+(3*4)
} 14
test expr-14.29 {CompilePrimaryExpr: error in subexpression primary} -body {
catch {expr 2+(3*[set])} msg
- set errorInfo
+ set ::errorInfo
} -match glob -result {wrong # args: should be "set varName ?newValue?"
while *ing
"set"*}
test expr-14.30 {CompilePrimaryExpr: missing paren in subexpression primary} -body {
- catch {expr 2+(3*(4+5)} msg
- set errorInfo
-} -match glob -result {syntax error in expression "2+(3*(4+5)": looking for close parenthesis
- while *ing
-"expr 2+(3*(4+5)"}
+ expr 2+(3*(4+5)
+} -returnCodes error -match glob -result *
test expr-14.31 {CompilePrimaryExpr: just var ref in subexpression primary} {
set i "5+10"
list "[expr $i] == 15" "[expr ($i)] == 15" "[eval expr ($i)] == 15"
} {{15 == 15} {15 == 15} {15 == 15}}
test expr-14.32 {CompilePrimaryExpr: unexpected token} -body {
- catch {expr @} msg
- set errorInfo
-} -match glob -result {syntax error in expression "@": character not legal in expressions
- while *ing
-"expr @"}
+ expr @
+} -returnCodes error -match glob -result *
test expr-15.1 {CompileMathFuncCall: missing parenthesis} -body {
- catch {expr sinh2.0)} msg
- set errorInfo
-} -match glob -result {syntax error in expression "sinh2.0)": * preceding $*
- while *ing
-"expr sinh2.0)"}
+ expr sinh2.0)
+} -returnCodes error -match glob -result *
test expr-15.2 {CompileMathFuncCall: unknown math function} -body {
catch {expr whazzathuh(1)} msg
- set errorInfo
+ set ::errorInfo
} -match glob -result {* "*whazzathuh"
while *ing
"expr whazzathuh(1)"}
test expr-15.3 {CompileMathFuncCall: too many arguments} -body {
catch {expr sin(1,2,3)} msg
- set errorInfo
+ set ::errorInfo
} -match glob -result {too many arguments for math function*
while *ing
"expr sin(1,2,3)"}
test expr-15.4 {CompileMathFuncCall: ')' found before last required arg} -body {
catch {expr sin()} msg
- set errorInfo
+ set ::errorInfo
} -match glob -result {too few arguments for math function*
while *ing
"expr sin()"}
test expr-15.5 {CompileMathFuncCall: too few arguments} -body {
catch {expr pow(1)} msg
- set errorInfo
+ set ::errorInfo
} -match glob -result {too few arguments for math function*
while *ing
"expr pow(1)"}
test expr-15.6 {CompileMathFuncCall: missing ')'} -body {
- catch {expr sin(1} msg
- set errorInfo
-} -match glob -result {syntax error in expression "sin(1": missing close parenthesis at end of function call
- while *ing
-"expr sin(1"}
+ expr sin(1
+} -returnCodes error -match glob -result *
test expr-15.7 {CompileMathFuncCall: call registered math function} {testmathfunctions} {
expr 2*T1()
} 246
@@ -766,9 +712,15 @@ test expr=15.14 {ExprCallMathFunc: call registered math function} {testmathfunct
test expr-15.15 {ExprCallMathFunc: call registered math function} {testmathfunctions} {
expr T3(21.0, wide(37))
} 37.0
-test expr=15.16 {ExprCallMathFunc: call registered math function} {testmathfunctions} {
+test expr-15.16 {ExprCallMathFunc: call registered math function} {testmathfunctions} {
expr T3(wide(21), 37.0)
} 37.0
+test expr-15.17 {ExprCallMathFunc: non-numeric arg} -constraints {
+ testmathfunctions
+} -body {
+ expr T3(0,"a")
+} -returnCodes error -result {argument to math function didn't have numeric value}
+
test expr-16.1 {GetToken: checks whether integer token starting with "0x" (e.g., "0x$") is invalid} {
catch {unset a}
@@ -836,7 +788,7 @@ test expr-20.1 {wrong brace matching} {
set cmd "expr $l$q|$q == $q$r$q$r"
list [catch $cmd a] $a
} {1 {extra characters after close-brace}}
-test expr-20.2 {double invocation of variable traces} {
+test expr-20.2 {double invocation of variable traces} -body {
set exprtracecounter 0
proc exprtraceproc {args} {
upvar #0 exprtracecounter counter
@@ -854,7 +806,7 @@ test expr-20.2 {double invocation of variable traces} {
list [catch {expr "$exprtracevar + 20"} a] $a \
[catch {expr "$exprtracevar + 20"} b] $b \
[unset exprtracevar exprtracecounter]
-} {1 {syntax error in expression "1 oops 10 + 20": extra tokens at end of expression} 0 32 {}}
+} -match glob -result {1 * 0 32 {}}
test expr-20.3 {broken substitution of integer digits} {
# fails with 8.0.x, but not 8.1b2
list [set a 000; expr 0x1$a] [set a 1; expr ${a}000]
@@ -887,9 +839,9 @@ test expr-21.9 {non-numeric boolean literals} {expr !off } 1
test expr-21.10 {non-numeric boolean literals} {expr !on } 0
test expr-21.11 {non-numeric boolean literals} {expr !no } 1
test expr-21.12 {non-numeric boolean literals} {expr !yes } 0
-test expr-21.13 {non-numeric boolean literals} {
- list [catch {expr !truef} err] $err
-} {1 {syntax error in expression "!truef": the word "truef" requires a preceding $ if it's a variable or function arguments if it's a function}}
+test expr-21.13 {non-numeric boolean literals} -body {
+ expr !truef
+} -returnCodes error -match glob -result *
test expr-21.14 {non-numeric boolean literals} {
list [catch {expr !"truef"} err] $err
} {1 {can't use non-numeric string as operand of "!"}}
@@ -965,18 +917,15 @@ test expr-23.2 {CompileExponentialExpr: just exponential expr} {expr 0xff**2} 65
test expr-23.3 {CompileExponentialExpr: just exponential expr} {expr -1**2} 1
test expr-23.4 {CompileExponentialExpr: just exponential expr} {expr 18**07} 612220032
test expr-23.5 {CompileExponentialExpr: error in exponential expr} -body {
- catch {expr x**3} msg
- set msg
-} -match glob -result {syntax error in expression "x**3": * preceding $*}
+ expr x**3
+} -returnCodes error -match glob -result *
test expr-23.6 {CompileExponentialExpr: simple expo exprs} {expr 0xff**0x3} 16581375
-test expr-23.7 {CompileExponentialExpr: error compiling expo arm} {
- catch {expr (-3-)**6} msg
- set msg
-} {syntax error in expression "(-3-)**6": unexpected close parenthesis}
+test expr-23.7 {CompileExponentialExpr: error compiling expo arm} -body {
+ expr (-3-)**6
+} -returnCodes error -match glob -result *
test expr-23.8 {CompileExponentialExpr: error compiling expo arm} -body {
- catch {expr 2**x} msg
- set msg
-} -match glob -result {syntax error in expression "2**x": * preceding $*}
+ expr 2**x
+} -returnCodes error -match glob -result *
test expr-23.9 {CompileExponentialExpr: runtime error} {
list [catch {expr {24.0**"xx"}} msg] $msg
} {1 {can't use non-numeric string as operand of "**"}}
@@ -1014,18 +963,486 @@ test expr-23.32 {INST_EXPON: special cases} {expr {wide(1)**wide(1234567)}} 1
test expr-23.33 {INST_EXPON: special cases} {expr {wide(2)**wide(-2)}} 0
test expr-23.34 {INST_EXPON: special cases} {expr {2**0}} 1
test expr-23.35 {INST_EXPON: special cases} {expr {wide(2)**0}} 1
+test expr-23.36 {INST_EXPON: big integer} {expr {10**17}} 1[string repeat 0 17]
+test expr-23.37 {INST_EXPON: big integer} {expr {10**18}} 1[string repeat 0 18]
+test expr-23.38 {INST_EXPON: big integer} {expr {10**19}} 1[string repeat 0 19]
+test expr-23.39 {INST_EXPON: big integer} {
+ expr 1[string repeat 0 30]**2
+} 1[string repeat 0 60]
+test expr-23.40 {INST_EXPON: overflow to big integer} {expr {(-10)**3}} -1000
+test expr-23.41 {INST_EXPON: overflow to big integer} {expr 2**64} [expr 1<<64]
+test expr-23.42 {INST_EXPON: overflow to big integer} {expr 4**32} [expr 1<<64]
+test expr-23.43 {INST_EXPON: overflow to big integer} {expr 16**16} [expr 1<<64]
+test expr-23.44 {INST_EXPON: overflow to big integer} {expr 256**8} [expr 1<<64]
+test expr-23.45 {INST_EXPON: Bug 1555371} {expr 2**1} 2
+test expr-23.46 {INST_EXPON: Bug 1561260} -body {
+ expr 5**28
+} -match glob -result *5
+test expr-23.47 {INST_EXPON: Bug 1561260} {
+ expr 2**32*5**32
+} 1[string repeat 0 32]
+test expr-23.48 {INST_EXPON: TIP 274: right assoc} {
+expr 2**3**4
+} 2417851639229258349412352
+test expr-23.49 {INST_EXPON: optimize powers of 2} {
+ set trouble {test powers of 2}
+ for {set tval 0} {$tval <= 66} {incr tval} {
+ set is [expr {2 ** $tval}]
+ set sb [expr {1 << $tval}]
+ if {$is != $sb} {
+ append trouble \n "2**" $tval " is " $is " should be " $sb
+ }
+ if {$tval >= 1} {
+ set is [expr {-2 ** $tval}]
+ set sb [expr {1 << $tval}]
+ if {$tval & 1} {
+ set sb [expr {-$sb}]
+ }
+ if {$is != $sb} {
+ append trouble \n "-2**" $tval " is " $is " should be " $sb
+ }
+ }
+ }
+ set trouble
+} {test powers of 2}
+test expr-23.50 {INST_EXPON: small powers of 32-bit integers} {
+ set trouble {test small powers of 32-bit ints}
+ for {set base 3} {$base <= 45} {incr base} {
+ set sb $base
+ set sbm [expr {-$base}]
+ for {set expt 2} {$expt <= 8} {incr expt} {
+ set sb [expr {$sb * $base}]
+ set is [expr {$base ** $expt}]
+ if {$sb != $is} {
+ append trouble \n $base ** $expt " is " $is " should be " $sb
+ }
+ set sbm [expr {-$sbm * $base}]
+ set ism [expr {(-$base) ** $expt}]
+ if {$sbm != $ism} {
+ append trouble \n - $base ** $expt " is " $ism \
+ " should be " $sbm
+ }
+ }
+ }
+ set trouble
+} {test small powers of 32-bit ints}
+test expr-23.51 {INST_EXPON: intermediate powers of 32-bit integers} {
+ set trouble {test intermediate powers of 32-bit ints}
+ for {set base 3} {$base <= 11} {incr base} {
+ set sb [expr {$base ** 8}]
+ set sbm $sb
+ for {set expt 9} {$expt <= 21} {incr expt} {
+ set sb [expr {$sb * $base}]
+ set sbm [expr {$sbm * -$base}]
+ set is [expr {$base ** $expt}]
+ set ism [expr {-$base ** $expt}]
+ if {$sb != $is} {
+ append trouble \n $base ** $expt " is " $is " should be " $sb
+ }
+ if {$sbm != $ism} {
+ append trouble \n - $base ** $expt " is " $ism \
+ " should be " $sbm
+ }
+ }
+ }
+ set trouble
+} {test intermediate powers of 32-bit ints}
+test expr-23.52 {INST_EXPON: small integer powers with 64-bit results} {
+ set trouble {test small int powers with 64-bit results}
+ for {set exp 2} {$exp <= 16} {incr exp} {
+ set base [expr {entier(pow(double(0x7fffffffffffffff),(1.0/$exp)))}]
+ set sb 1
+ set sbm 1
+ for {set i 0} {$i < $exp} {incr i} {
+ set sb [expr {$sb * $base}]
+ set sbm [expr {$sbm * -$base}]
+ }
+ set is [expr {$base ** $exp}]
+ set ism [expr {-$base ** $exp}]
+ if {$sb != $is} {
+ append trouble \n $base ** $exp " is " $is " should be " $sb
+ }
+ if {$sbm != $ism} {
+ append trouble \n - $base ** $exp " is " $ism " should be " $sbm
+ }
+ incr base
+ set sb 1
+ set sbm 1
+ for {set i 0} {$i < $exp} {incr i} {
+ set sb [expr {$sb * $base}]
+ set sbm [expr {$sbm * -$base}]
+ }
+ set is [expr {$base ** $exp}]
+ set ism [expr {-$base ** $exp}]
+ if {$sb != $is} {
+ append trouble \n $base ** $exp " is " $is " should be " $sb
+ }
+ if {$sbm != $ism} {
+ append trouble \n - $base ** $exp " is " $ism " should be " $sbm
+ }
+ }
+ set trouble
+} {test small int powers with 64-bit results}
+test expr-23.53 {INST_EXPON: intermediate powers of 64-bit integers} {
+ set trouble {test intermediate powers of 64-bit ints}
+ for {set base 3} {$base <= 13} {incr base} {
+ set sb [expr {$base ** 15}]
+ set sbm [expr {-$sb}]
+ for {set expt 16} {$expt <= 39} {incr expt} {
+ set sb [expr {$sb * $base}]
+ set sbm [expr {$sbm * -$base}]
+ set is [expr {$base ** $expt}]
+ set ism [expr {-$base ** $expt}]
+ if {$sb != $is} {
+ append trouble \n $base ** $expt " is " $is " should be " $sb
+ }
+ if {$sbm != $ism} {
+ append trouble \n - $base ** $expt " is " $ism \
+ " should be " $sbm
+ }
+ }
+ }
+ set trouble
+} {test intermediate powers of 64-bit ints}
+test expr-23.54.0 {INST_EXPON: Bug 2798543} {
+ expr {3**9 == 3**65545}
+} 0
+test expr-23.54.1 {INST_EXPON: Bug 2798543} {
+ expr {3**10 == 3**65546}
+} 0
+test expr-23.54.2 {INST_EXPON: Bug 2798543} {
+ expr {3**11 == 3**65547}
+} 0
+test expr-23.54.3 {INST_EXPON: Bug 2798543} {
+ expr {3**12 == 3**65548}
+} 0
+test expr-23.54.4 {INST_EXPON: Bug 2798543} {
+ expr {3**13 == 3**65549}
+} 0
+test expr-23.54.5 {INST_EXPON: Bug 2798543} {
+ expr {3**14 == 3**65550}
+} 0
+test expr-23.54.6 {INST_EXPON: Bug 2798543} {
+ expr {3**15 == 3**65551}
+} 0
+test expr-23.54.7 {INST_EXPON: Bug 2798543} {
+ expr {3**16 == 3**65552}
+} 0
+test expr-23.54.8 {INST_EXPON: Bug 2798543} {
+ expr {3**17 == 3**65553}
+} 0
+test expr-23.54.9 {INST_EXPON: Bug 2798543} {
+ expr {3**18 == 3**65554}
+} 0
+test expr-23.54.10 {INST_EXPON: Bug 2798543} {
+ expr {3**19 == 3**65555}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.54.13 {INST_EXPON: Bug 2798543} {
+ expr {(-3)**9 == (-3)**65545}
+} 0
+test expr-23.55.0 {INST_EXPON: Bug 2798543} {
+ expr {4**9 == 4**65545}
+} 0
+test expr-23.55.1 {INST_EXPON: Bug 2798543} {
+ expr {4**15 == 4**65551}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.55.4 {INST_EXPON: Bug 2798543} {
+ expr {(-4)**9 == (-4)**65545}
+} 0
+test expr-23.56.0 {INST_EXPON: Bug 2798543} {
+ expr {5**9 == 5**65545}
+} 0
+test expr-23.56.1 {INST_EXPON: Bug 2798543} {
+ expr {5**13 == 5**65549}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.56.4 {INST_EXPON: Bug 2798543} {
+ expr {(-5)**9 == (-5)**65545}
+} 0
+test expr-23.57.0 {INST_EXPON: Bug 2798543} {
+ expr {6**9 == 6**65545}
+} 0
+test expr-23.57.1 {INST_EXPON: Bug 2798543} {
+ expr {6**11 == 6**65547}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.57.4 {INST_EXPON: Bug 2798543} {
+ expr {(-6)**9 == (-6)**65545}
+} 0
+test expr-23.58.0 {INST_EXPON: Bug 2798543} {
+ expr {7**9 == 7**65545}
+} 0
+test expr-23.58.1 {INST_EXPON: Bug 2798543} {
+ expr {7**11 == 7**65547}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.58.4 {INST_EXPON: Bug 2798543} {
+ expr {(-7)**9 == (-7)**65545}
+} 0
+test expr-23.59.0 {INST_EXPON: Bug 2798543} {
+ expr {8**9 == 8**65545}
+} 0
+test expr-23.59.1 {INST_EXPON: Bug 2798543} {
+ expr {8**10 == 8**65546}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.59.4 {INST_EXPON: Bug 2798543} {
+ expr {(-8)**9 == (-8)**65545}
+} 0
+test expr-23.60.0 {INST_EXPON: Bug 2798543} {
+ expr {9**9 == 9**65545}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.60.3 {INST_EXPON: Bug 2798543} {
+ expr {(-9)**9 == (-9)**65545}
+} 0
+test expr-23.61.0 {INST_EXPON: Bug 2798543} {
+ expr {10**9 == 10**65545}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.61.3 {INST_EXPON: Bug 2798543} {
+ expr {(-10)**9 == (-10)**65545}
+} 0
+test expr-23.62.0 {INST_EXPON: Bug 2798543} {
+ expr {11**9 == 11**65545}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.62.3 {INST_EXPON: Bug 2798543} {
+ expr {(-11)**9 == (-11)**65545}
+} 0
+test expr-23.63.0 {INST_EXPON: Bug 2798543} {
+ expr {3**20 == 3**65556}
+} 0
+test expr-23.63.1 {INST_EXPON: Bug 2798543} {
+ expr {3**39 == 3**65575}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.63.4 {INST_EXPON: Bug 2798543} {
+ expr {(-3)**20 == (-3)**65556}
+} 0
+test expr-23.64.0 {INST_EXPON: Bug 2798543} {
+ expr {4**17 == 4**65553}
+} 0
+test expr-23.64.1 {INST_EXPON: Bug 2798543} {
+ expr {4**31 == 4**65567}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.64.4 {INST_EXPON: Bug 2798543} {
+ expr {(-4)**17 == (-4)**65553}
+} 0
+test expr-23.65.0 {INST_EXPON: Bug 2798543} {
+ expr {5**17 == 5**65553}
+} 0
+test expr-23.65.1 {INST_EXPON: Bug 2798543} {
+ expr {5**27 == 5**65563}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.65.4 {INST_EXPON: Bug 2798543} {
+ expr {(-5)**17 == (-5)**65553}
+} 0
+test expr-23.66.0 {INST_EXPON: Bug 2798543} {
+ expr {6**17 == 6**65553}
+} 0
+test expr-23.66.1 {INST_EXPON: Bug 2798543} {
+ expr {6**24 == 6**65560}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.66.4 {INST_EXPON: Bug 2798543} {
+ expr {(-6)**17 == (-6)**65553}
+} 0
+test expr-23.67.0 {INST_EXPON: Bug 2798543} {
+ expr {7**17 == 7**65553}
+} 0
+test expr-23.67.1 {INST_EXPON: Bug 2798543} {
+ expr {7**22 == 7**65558}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.67.4 {INST_EXPON: Bug 2798543} {
+ expr {(-7)**17 == (-7)**65553}
+} 0
+test expr-23.68.0 {INST_EXPON: Bug 2798543} {
+ expr {8**17 == 8**65553}
+} 0
+test expr-23.68.1 {INST_EXPON: Bug 2798543} {
+ expr {8**20 == 8**65556}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.68.4 {INST_EXPON: Bug 2798543} {
+ expr {(-8)**17 == (-8)**65553}
+} 0
+test expr-23.69.0 {INST_EXPON: Bug 2798543} {
+ expr {9**17 == 9**65553}
+} 0
+test expr-23.69.1 {INST_EXPON: Bug 2798543} {
+ expr {9**19 == 9**65555}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.69.4 {INST_EXPON: Bug 2798543} {
+ expr {(-9)**17 == (-9)**65553}
+} 0
+test expr-23.70.0 {INST_EXPON: Bug 2798543} {
+ expr {10**17 == 10**65553}
+} 0
+test expr-23.70.1 {INST_EXPON: Bug 2798543} {
+ expr {10**18 == 10**65554}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.70.4 {INST_EXPON: Bug 2798543} {
+ expr {(-10)**17 == (-10)**65553}
+} 0
+test expr-23.71.0 {INST_EXPON: Bug 2798543} {
+ expr {11**17 == 11**65553}
+} 0
+test expr-23.71.1 {INST_EXPON: Bug 2798543} {
+ expr {11**18 == 11**65554}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.71.4 {INST_EXPON: Bug 2798543} {
+ expr {(-11)**17 == (-11)**65553}
+} 0
+test expr-23.72.0 {INST_EXPON: Bug 2798543} {
+ expr {12**17 == 12**65553}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.72.3 {INST_EXPON: Bug 2798543} {
+ expr {(-12)**17 == (-12)**65553}
+} 0
+test expr-23.73.0 {INST_EXPON: Bug 2798543} {
+ expr {13**17 == 13**65553}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.73.3 {INST_EXPON: Bug 2798543} {
+ expr {(-13)**17 == (-13)**65553}
+} 0
+test expr-23.74.0 {INST_EXPON: Bug 2798543} {
+ expr {14**17 == 14**65553}
+} 0
+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}
+} -returnCodes error -result {exponent too large}
+test expr-23.74.3 {INST_EXPON: Bug 2798543} {
+ expr {(-14)**17 == (-14)**65553}
+} 0
+
# Some compilers get this wrong; ensure that we work around it correctly
test expr-24.1 {expr edge cases; shifting} {expr int(5)>>32} 0
test expr-24.2 {expr edge cases; shifting} {expr int(5)>>63} 0
test expr-24.3 {expr edge cases; shifting} {expr wide(5)>>32} 0
test expr-24.4 {expr edge cases; shifting} {expr wide(5)>>63} 0
-test expr-24.5 {expr edge cases; shifting} longIs32bit {expr int(5)<<32} 0
-test expr-24.6 {expr edge cases; shifting} longIs32bit {expr int(5)<<63} 0
+test expr-24.5 {expr edge cases; shifting} longIs32bit {expr int(5<<32)} 0
+test expr-24.6 {expr edge cases; shifting} longIs32bit {expr int(5<<63)} 0
test expr-24.7 {expr edge cases; shifting} {expr wide(5)<<32} 21474836480
-test expr-24.8 {expr edge cases; shifting} {expr wide(10)<<63} 0
+test expr-24.8 {expr edge cases; shifting} {expr wide(10<<63)} 0
test expr-24.9 {expr edge cases; shifting} {expr 5>>32} 0
+test expr-24.10 {INST_LSHIFT: Bug 1567222} {expr 500000000000000<<28} 134217728000000000000000
+
# List membership tests
test expr-25.1 {'in' operator} {expr {"a" in "a b c"}} 1
test expr-25.2 {'in' operator} {expr {"a" in "b a c"}} 1
@@ -5400,7 +5817,20 @@ test expr-32.2 {expr div basics} {
-3 -2 -1 -1 -1 \
]
-test expr-33.1 {parse largest long value} {longIs32bit} {
+test expr-32.3 {Bug 1585704} {
+ expr 1%(1<<63)
+} 1
+test expr-32.4 {Bug 1585704} {
+ expr -1%(1<<63)
+} [expr (1<<63)-1]
+test expr-32.5 {Bug 1585704} {
+ expr (1<<32)%(1<<63)
+} [expr 1<<32]
+test expr-32.6 {Bug 1585704} {
+ expr -(1<<32)%(1<<63)
+} [expr (1<<63)-(1<<32)]
+
+test expr-33.1 {parse largest long value} longIs32bit {
set max_long_str 2147483647
set max_long_hex "0x7FFFFFFF "
@@ -5414,10 +5844,10 @@ test expr-33.1 {parse largest long value} {longIs32bit} {
[expr {$max_long + 0}] \
[expr {2147483647 + 0}] \
[expr {$max_long == $max_long_hex}] \
- [expr {(2147483647 + 1) < 0}] \
+ [expr {int(2147483647 + 1) < 0}] \
} {2147483647 2147483647 2147483647 2147483647 1 1}
-test expr-33.2 {parse smallest long value} {longIs32bit} {
+test expr-33.2 {parse smallest long value} longIs32bit {
set min_long_str -2147483648
set min_long_hex "-0x80000000 "
@@ -5434,10 +5864,10 @@ test expr-33.2 {parse smallest long value} {longIs32bit} {
[expr {$min_long + 0}] \
[expr {-2147483648 + 0}] \
[expr {$min_long == $min_long_hex}] \
- [expr {(-2147483648 - 1) == 0x7FFFFFFF}] \
+ [expr {int(-2147483648 - 1) == 0x7FFFFFFF}] \
} {-2147483648 -2147483648 -2147483648 -2147483648 1 1}
-test expr-33.3 {parse largest wide value} {wideIs64bit} {
+test expr-33.3 {parse largest wide value} wideIs64bit {
set max_wide_str 9223372036854775807
set max_wide_hex "0x7FFFFFFFFFFFFFFF "
@@ -5451,10 +5881,10 @@ test expr-33.3 {parse largest wide value} {wideIs64bit} {
[expr {$max_wide + 0}] \
[expr {9223372036854775807 + 0}] \
[expr {$max_wide == $max_wide_hex}] \
- [expr {(9223372036854775807 + 1) < 0}] \
+ [expr {wide(9223372036854775807 + 1) < 0}] \
} {9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 1 1}
-test expr-33.4 {parse smallest wide value} {wideIs64bit} {
+test expr-33.4 {parse smallest wide value} wideIs64bit {
set min_wide_str -9223372036854775808
set min_wide_hex "-0x8000000000000000 "
@@ -5471,351 +5901,351 @@ test expr-33.4 {parse smallest wide value} {wideIs64bit} {
[expr {$min_wide + 0}] \
[expr {-9223372036854775808 + 0}] \
[expr {$min_wide == $min_wide_hex}] \
- [expr {(-9223372036854775808 - 1) == 0x7FFFFFFFFFFFFFFF}] \
+ [expr {wide(-9223372036854775808 - 1) == 0x7FFFFFFFFFFFFFFF}] \
} {-9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 1 1}
set min -2147483648
set max 2147483647
-test expr-34.1 {expr edge cases} {longIs32bit} {
+test expr-34.1 {expr edge cases} {
expr {$min / $min}
} {1}
-test expr-34.2 {expr edge cases} {longIs32bit} {
+test expr-34.2 {expr edge cases} {
expr {$min % $min}
} {0}
-test expr-34.3 {expr edge cases} {longIs32bit} {
+test expr-34.3 {expr edge cases} {
expr {$min / ($min + 1)}
} {1}
-test expr-34.4 {expr edge cases} {longIs32bit} {
+test expr-34.4 {expr edge cases} {
expr {$min % ($min + 1)}
} {-1}
-test expr-34.5 {expr edge cases} {longIs32bit} {
+test expr-34.5 {expr edge cases} {
expr {$min / ($min + 2)}
} {1}
-test expr-34.6 {expr edge cases} {longIs32bit} {
+test expr-34.6 {expr edge cases} {
expr {$min % ($min + 2)}
} {-2}
-test expr-34.7 {expr edge cases} {longIs32bit} {
+test expr-34.7 {expr edge cases} {
expr {$min / ($min + 3)}
} {1}
-test expr-34.8 {expr edge cases} {longIs32bit} {
+test expr-34.8 {expr edge cases} {
expr {$min % ($min + 3)}
} {-3}
-test expr-34.9 {expr edge cases} {longIs32bit} {
+test expr-34.9 {expr edge cases} {
expr {$min / -3}
} {715827882}
-test expr-34.10 {expr edge cases} {longIs32bit} {
+test expr-34.10 {expr edge cases} {
expr {$min % -3}
} {-2}
-test expr-34.11 {expr edge cases} {longIs32bit} {
+test expr-34.11 {expr edge cases} {
expr {$min / -2}
} {1073741824}
-test expr-34.12 {expr edge cases} {longIs32bit} {
+test expr-34.12 {expr edge cases} {
expr {$min % -2}
} {0}
-test expr-34.13 {expr edge cases} {longIs32bit} {
- expr {$min / -1}
+test expr-34.13 {expr edge cases} longIs32bit {
+ expr {int($min / -1)}
} {-2147483648}
-test expr-34.14 {expr edge cases} {longIs32bit} {
+test expr-34.14 {expr edge cases} {
expr {$min % -1}
} {0}
-test expr-34.15 {expr edge cases} {longIs32bit} {
- expr {$min * -1}
+test expr-34.15 {expr edge cases} longIs32bit {
+ expr {int($min * -1)}
} $min
-test expr-34.16 {expr edge cases} {longIs32bit} {
- expr {-$min}
+test expr-34.16 {expr edge cases} longIs32bit {
+ expr {int(-$min)}
} $min
-test expr-34.17 {expr edge cases} {longIs32bit} {
+test expr-34.17 {expr edge cases} {
expr {$min / 1}
} $min
-test expr-34.18 {expr edge cases} {longIs32bit} {
+test expr-34.18 {expr edge cases} {
expr {$min % 1}
} {0}
-test expr-34.19 {expr edge cases} {longIs32bit} {
+test expr-34.19 {expr edge cases} {
expr {$min / 2}
} {-1073741824}
-test expr-34.20 {expr edge cases} {longIs32bit} {
+test expr-34.20 {expr edge cases} {
expr {$min % 2}
} {0}
-test expr-34.21 {expr edge cases} {longIs32bit} {
+test expr-34.21 {expr edge cases} {
expr {$min / 3}
} {-715827883}
-test expr-34.22 {expr edge cases} {longIs32bit} {
+test expr-34.22 {expr edge cases} {
expr {$min % 3}
} {1}
-test expr-34.23 {expr edge cases} {longIs32bit} {
+test expr-34.23 {expr edge cases} {
expr {$min / ($max - 3)}
} {-2}
-test expr-34.24 {expr edge cases} {longIs32bit} {
+test expr-34.24 {expr edge cases} {
expr {$min % ($max - 3)}
} {2147483640}
-test expr-34.25 {expr edge cases} {longIs32bit} {
+test expr-34.25 {expr edge cases} {
expr {$min / ($max - 2)}
} {-2}
-test expr-34.26 {expr edge cases} {longIs32bit} {
+test expr-34.26 {expr edge cases} {
expr {$min % ($max - 2)}
} {2147483642}
-test expr-34.27 {expr edge cases} {longIs32bit} {
+test expr-34.27 {expr edge cases} {
expr {$min / ($max - 1)}
} {-2}
-test expr-34.28 {expr edge cases} {longIs32bit} {
+test expr-34.28 {expr edge cases} {
expr {$min % ($max - 1)}
} {2147483644}
-test expr-34.29 {expr edge cases} {longIs32bit} {
+test expr-34.29 {expr edge cases} {
expr {$min / $max}
} {-2}
-test expr-34.30 {expr edge cases} {longIs32bit} {
+test expr-34.30 {expr edge cases} {
expr {$min % $max}
} {2147483646}
-test expr-34.31 {expr edge cases} {longIs32bit} {
+test expr-34.31 {expr edge cases} {
expr {$max / $max}
} {1}
-test expr-34.32 {expr edge cases} {longIs32bit} {
+test expr-34.32 {expr edge cases} {
expr {$max % $max}
} {0}
-test expr-34.33 {expr edge cases} {longIs32bit} {
+test expr-34.33 {expr edge cases} {
expr {$max / ($max - 1)}
} {1}
-test expr-34.34 {expr edge cases} {longIs32bit} {
+test expr-34.34 {expr edge cases} {
expr {$max % ($max - 1)}
} {1}
-test expr-34.35 {expr edge cases} {longIs32bit} {
+test expr-34.35 {expr edge cases} {
expr {$max / ($max - 2)}
} {1}
-test expr-34.36 {expr edge cases} {longIs32bit} {
+test expr-34.36 {expr edge cases} {
expr {$max % ($max - 2)}
} {2}
-test expr-34.37 {expr edge cases} {longIs32bit} {
+test expr-34.37 {expr edge cases} {
expr {$max / ($max - 3)}
} {1}
-test expr-34.38 {expr edge cases} {longIs32bit} {
+test expr-34.38 {expr edge cases} {
expr {$max % ($max - 3)}
} {3}
-test expr-34.39 {expr edge cases} {longIs32bit} {
+test expr-34.39 {expr edge cases} {
expr {$max / 3}
} {715827882}
-test expr-34.40 {expr edge cases} {longIs32bit} {
+test expr-34.40 {expr edge cases} {
expr {$max % 3}
} {1}
-test expr-34.41 {expr edge cases} {longIs32bit} {
+test expr-34.41 {expr edge cases} {
expr {$max / 2}
} {1073741823}
-test expr-34.42 {expr edge cases} {longIs32bit} {
+test expr-34.42 {expr edge cases} {
expr {$max % 2}
} {1}
-test expr-34.43 {expr edge cases} {longIs32bit} {
+test expr-34.43 {expr edge cases} {
expr {$max / 1}
} $max
-test expr-34.44 {expr edge cases} {longIs32bit} {
+test expr-34.44 {expr edge cases} {
expr {$max % 1}
} {0}
-test expr-34.45 {expr edge cases} {longIs32bit} {
+test expr-34.45 {expr edge cases} {
expr {$max / -1}
} "-$max"
-test expr-34.46 {expr edge cases} {longIs32bit} {
+test expr-34.46 {expr edge cases} {
expr {$max % -1}
} {0}
-test expr-34.47 {expr edge cases} {longIs32bit} {
+test expr-34.47 {expr edge cases} {
expr {$max / -2}
} {-1073741824}
-test expr-34.48 {expr edge cases} {longIs32bit} {
+test expr-34.48 {expr edge cases} {
expr {$max % -2}
} {-1}
-test expr-34.49 {expr edge cases} {longIs32bit} {
+test expr-34.49 {expr edge cases} {
expr {$max / -3}
} {-715827883}
-test expr-34.50 {expr edge cases} {longIs32bit} {
+test expr-34.50 {expr edge cases} {
expr {$max % -3}
} {-2}
-test expr-34.51 {expr edge cases} {longIs32bit} {
+test expr-34.51 {expr edge cases} {
expr {$max / ($min + 3)}
} {-2}
-test expr-34.52 {expr edge cases} {longIs32bit} {
+test expr-34.52 {expr edge cases} {
expr {$max % ($min + 3)}
} {-2147483643}
-test expr-34.53 {expr edge cases} {longIs32bit} {
+test expr-34.53 {expr edge cases} {
expr {$max / ($min + 2)}
} {-2}
-test expr-34.54 {expr edge cases} {longIs32bit} {
+test expr-34.54 {expr edge cases} {
expr {$max % ($min + 2)}
} {-2147483645}
-test expr-34.55 {expr edge cases} {longIs32bit} {
+test expr-34.55 {expr edge cases} {
expr {$max / ($min + 1)}
} {-1}
-test expr-34.56 {expr edge cases} {longIs32bit} {
+test expr-34.56 {expr edge cases} {
expr {$max % ($min + 1)}
} {0}
-test expr-34.57 {expr edge cases} {longIs32bit} {
+test expr-34.57 {expr edge cases} {
expr {$max / $min}
} {-1}
-test expr-34.58 {expr edge cases} {longIs32bit} {
+test expr-34.58 {expr edge cases} {
expr {$max % $min}
} {-1}
-test expr-34.59 {expr edge cases} {longIs32bit} {
+test expr-34.59 {expr edge cases} {
expr {($min + 1) / ($max - 1)}
} {-2}
-test expr-34.60 {expr edge cases} {longIs32bit} {
+test expr-34.60 {expr edge cases} {
expr {($min + 1) % ($max - 1)}
} {2147483645}
-test expr-34.61 {expr edge cases} {longIs32bit} {
+test expr-34.61 {expr edge cases} {
expr {($max - 1) / ($min + 1)}
} {-1}
-test expr-34.62 {expr edge cases} {longIs32bit} {
+test expr-34.62 {expr edge cases} {
expr {($max - 1) % ($min + 1)}
} {-1}
-test expr-34.63 {expr edge cases} {longIs32bit} {
+test expr-34.63 {expr edge cases} {
expr {($max - 1) / $min}
} {-1}
-test expr-34.64 {expr edge cases} {longIs32bit} {
+test expr-34.64 {expr edge cases} {
expr {($max - 1) % $min}
} {-2}
-test expr-34.65 {expr edge cases} {longIs32bit} {
+test expr-34.65 {expr edge cases} {
expr {($max - 2) / $min}
} {-1}
-test expr-34.66 {expr edge cases} {longIs32bit} {
+test expr-34.66 {expr edge cases} {
expr {($max - 2) % $min}
} {-3}
-test expr-34.67 {expr edge cases} {longIs32bit} {
+test expr-34.67 {expr edge cases} {
expr {($max - 3) / $min}
} {-1}
-test expr-34.68 {expr edge cases} {longIs32bit} {
+test expr-34.68 {expr edge cases} {
expr {($max - 3) % $min}
} {-4}
-test expr-34.69 {expr edge cases} {longIs32bit} {
+test expr-34.69 {expr edge cases} {
expr {-3 / $min}
} {0}
-test expr-34.70 {expr edge cases} {longIs32bit} {
+test expr-34.70 {expr edge cases} {
expr {-3 % $min}
} {-3}
-test expr-34.71 {expr edge cases} {longIs32bit} {
+test expr-34.71 {expr edge cases} {
expr {-2 / $min}
} {0}
-test expr-34.72 {expr edge cases} {longIs32bit} {
+test expr-34.72 {expr edge cases} {
expr {-2 % $min}
} {-2}
-test expr-34.73 {expr edge cases} {longIs32bit} {
+test expr-34.73 {expr edge cases} {
expr {-1 / $min}
} {0}
-test expr-34.74 {expr edge cases} {longIs32bit} {
+test expr-34.74 {expr edge cases} {
expr {-1 % $min}
} {-1}
-test expr-34.75 {expr edge cases} {longIs32bit} {
+test expr-34.75 {expr edge cases} {
expr {0 / $min}
} {0}
-test expr-34.76 {expr edge cases} {longIs32bit} {
+test expr-34.76 {expr edge cases} {
expr {0 % $min}
} {0}
-test expr-34.77 {expr edge cases} {longIs32bit} {
+test expr-34.77 {expr edge cases} {
expr {0 / ($min + 1)}
} {0}
-test expr-34.78 {expr edge cases} {longIs32bit} {
+test expr-34.78 {expr edge cases} {
expr {0 % ($min + 1)}
} {0}
-test expr-34.79 {expr edge cases} {longIs32bit} {
+test expr-34.79 {expr edge cases} {
expr {1 / $min}
} {-1}
-test expr-34.80 {expr edge cases} {longIs32bit} {
+test expr-34.80 {expr edge cases} {
expr {1 % $min}
} {-2147483647}
-test expr-34.81 {expr edge cases} {longIs32bit} {
+test expr-34.81 {expr edge cases} {
expr {1 / ($min + 1)}
} {-1}
-test expr-34.82 {expr edge cases} {longIs32bit} {
+test expr-34.82 {expr edge cases} {
expr {1 % ($min + 1)}
} {-2147483646}
-test expr-34.83 {expr edge cases} {longIs32bit} {
+test expr-34.83 {expr edge cases} {
expr {2 / $min}
} {-1}
-test expr-34.84 {expr edge cases} {longIs32bit} {
+test expr-34.84 {expr edge cases} {
expr {2 % $min}
} {-2147483646}
-test expr-34.85 {expr edge cases} {longIs32bit} {
+test expr-34.85 {expr edge cases} {
expr {2 / ($min + 1)}
} {-1}
-test expr-34.86 {expr edge cases} {longIs32bit} {
+test expr-34.86 {expr edge cases} {
expr {2 % ($min + 1)}
} {-2147483645}
-test expr-34.87 {expr edge cases} {longIs32bit} {
+test expr-34.87 {expr edge cases} {
expr {3 / $min}
} {-1}
-test expr-34.88 {expr edge cases} {longIs32bit} {
+test expr-34.88 {expr edge cases} {
expr {3 % $min}
} {-2147483645}
-test expr-34.89 {expr edge cases} {longIs32bit} {
+test expr-34.89 {expr edge cases} {
expr {3 / ($min + 1)}
} {-1}
-test expr-34.90 {expr edge cases} {longIs32bit} {
+test expr-34.90 {expr edge cases} {
expr {3 % ($min + 1)}
} {-2147483644}
# Euclidean property:
# quotient * divisor + remainder = dividend
-test expr-35.1 {expr edge cases} {longIs32bit} {
+test expr-35.1 {expr edge cases} {
set dividend $max
set divisor 2
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($divisor * $q) + $r}]
} {1073741823 * 2 + 1 = 2147483647}
-test expr-35.2 {expr edge cases} {longIs32bit} {
+test expr-35.2 {expr edge cases} {
set dividend [expr {$max - 1}]
set divisor 2
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {1073741823 * 2 + 0 = 2147483646}
-test expr-35.3 {expr edge cases} {longIs32bit} {
+test expr-35.3 {expr edge cases} {
set dividend [expr {$max - 2}]
set divisor 2
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {1073741822 * 2 + 1 = 2147483645}
-test expr-35.4 {expr edge cases} {longIs32bit} {
+test expr-35.4 {expr edge cases} {
set dividend $max
set divisor 3
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {715827882 * 3 + 1 = 2147483647}
-test expr-35.5 {expr edge cases} {longIs32bit} {
+test expr-35.5 {expr edge cases} {
set dividend [expr {$max - 1}]
set divisor 3
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {715827882 * 3 + 0 = 2147483646}
-test expr-35.6 {expr edge cases} {longIs32bit} {
+test expr-35.6 {expr edge cases} {
set dividend [expr {$max - 2}]
set divisor 3
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {715827881 * 3 + 2 = 2147483645}
-test expr-35.7 {expr edge cases} {longIs32bit} {
+test expr-35.7 {expr edge cases} {
set dividend $min
set divisor 2
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {-1073741824 * 2 + 0 = -2147483648}
-test expr-35.8 {expr edge cases} {longIs32bit} {
+test expr-35.8 {expr edge cases} {
set dividend [expr {$min + 1}]
set divisor 2
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {-1073741824 * 2 + 1 = -2147483647}
-test expr-35.9 {expr edge cases} {longIs32bit} {
+test expr-35.9 {expr edge cases} {
set dividend [expr {$min + 2}]
set divisor 2
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {-1073741823 * 2 + 0 = -2147483646}
-test expr-35.10 {expr edge cases} {longIs32bit} {
+test expr-35.10 {expr edge cases} {
# Two things could happen here. The multiplication
# could overflow a 32 bit type, so that when
# 1 is added it overflows again back to min.
@@ -5828,28 +6258,28 @@ test expr-35.10 {expr edge cases} {longIs32bit} {
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {-715827883 * 3 + 1 = -2147483648}
-test expr-35.11 {expr edge cases} {longIs32bit} {
+test expr-35.11 {expr edge cases} {
set dividend $min
set divisor -3
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {715827882 * -3 + -2 = -2147483648}
-test expr-35.12 {expr edge cases} {longIs32bit} {
+test expr-35.12 {expr edge cases} {
set dividend $min
set divisor $min
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {1 * -2147483648 + 0 = -2147483648}
-test expr-35.13 {expr edge cases} {longIs32bit} {
+test expr-35.13 {expr edge cases} {
set dividend $min
set divisor [expr {$min + 1}]
set q [expr {$dividend / $divisor}]
set r [expr {$dividend % $divisor}]
list $q * $divisor + $r = [expr {($q * $divisor) + $r}]
} {1 * -2147483647 + -1 = -2147483648}
-test expr-35.14 {expr edge cases} {longIs32bit} {
+test expr-35.14 {expr edge cases} {
set dividend $min
set divisor [expr {$min + 2}]
set q [expr {$dividend / $divisor}]
@@ -5898,17 +6328,17 @@ test expr-36.11 {expr edge cases} {wideIs64bit} {
test expr-36.12 {expr edge cases} {wideIs64bit} {
expr {$min % -2}
} {0}
-test expr-36.13 {expr edge cases} {wideIs64bit} {
- expr {$min / -1}
+test expr-36.13 {expr edge cases} wideIs64bit {
+ expr {wide($min / -1)}
} $min
test expr-36.14 {expr edge cases} {wideIs64bit} {
expr {$min % -1}
} {0}
-test expr-36.15 {expr edge cases} {wideIs64bit} {
- expr {$min * -1}
+test expr-36.15 {expr edge cases} wideIs64bit {
+ expr {wide($min * -1)}
} $min
-test expr-36.16 {expr edge cases} {wideIs64bit} {
- expr {-$min}
+test expr-36.16 {expr edge cases} wideIs64bit {
+ expr {wide(-$min)}
} $min
test expr-36.17 {expr edge cases} {wideIs64bit} {
expr {$min / 1}
@@ -6238,6 +6668,277 @@ test expr-37.14 {expr edge cases} {wideIs64bit} {
test expr-38.1 {abs of smallest 32-bit integer [Bug 1241572]} {wideIs64bit} {
expr {abs(-2147483648)}
} 2147483648
+test expr-38.2 {abs and -0 [Bug 1893815]} {
+ expr {abs(-0)}
+} 0
+test expr-38.3 {abs and -0 [Bug 1893815]} {
+ expr {abs(-0.0)}
+} 0.0
+test expr-38.4 {abs and -0 [Bug 1893815]} {
+ expr {abs(-1e-324)}
+} 0.0
+test expr-38.5 {abs and -0 [Bug 1893815]} {
+ ::tcl::mathfunc::abs -0
+} 0
+test expr-38.6 {abs and -0 [Bug 1893815]} {
+ ::tcl::mathfunc::abs -0.0
+} 0.0
+test expr-38.7 {abs and -0 [Bug 1893815]} {
+ ::tcl::mathfunc::abs -1e-324
+} 0.0
+test expr-38.8 {abs and 0.0 [Bug 2954959]} {
+ ::tcl::mathfunc::abs 0.0
+} 0.0
+test expr-38.9 {abs and 0.0 [Bug 2954959]} {
+ expr {abs(0.0)}
+} 0.0
+test expr-38.10 {abs and -0x0 [Bug 2954959]} {
+ expr {abs(-0x0)}
+} 0
+test expr-38.11 {abs and 0x0 [Bug 2954959]} {
+ ::tcl::mathfunc::abs { 0x0}
+} { 0x0}
+test expr-38.12 {abs and -0x0 [Bug 2954959]} {
+ ::tcl::mathfunc::abs { -0x0}
+} 0
+test expr-38.13 {abs and 0.0 [Bug 2954959]} {
+ ::tcl::mathfunc::abs 1e-324
+} 1e-324
+
+testConstraint testexprlongobj [llength [info commands testexprlongobj]]
+testConstraint testexprdoubleobj [llength [info commands testexprdoubleobj]]
+
+test expr-39.1 {Check that Tcl_ExprLongObj doesn't modify interpreter result if no error} testexprlongobj {
+ testexprlongobj 4+1
+} {This is a result: 5}
+#Check for [Bug 1109484]
+test expr-39.2 {Tcl_ExprLongObj handles wide ints gracefully} testexprlongobj {
+ testexprlongobj wide(1)+2
+} {This is a result: 3}
+
+test expr-39.3 {Tcl_ExprLongObj on the empty string} \
+ -constraints {testexprlongobj}\
+ -body {testexprlongobj ""} \
+ -match glob \
+ -returnCodes error -result *
+test expr-39.4 {Tcl_ExprLongObj coerces doubles} testexprlongobj {
+ testexprlongobj 3+.14159
+} {This is a result: 3}
+test expr-39.5 {Tcl_ExprLongObj handles overflows} {testexprlongobj longIs32bit} {
+ testexprlongobj 0x80000000
+} {This is a result: -2147483648}
+test expr-39.6 {Tcl_ExprLongObj handles overflows} {testexprlongobj longIs32bit} {
+ testexprlongobj 0xffffffff
+} {This is a result: -1}
+test expr-39.7 {Tcl_ExprLongObj handles overflows} \
+ -constraints {testexprlongobj longIs32bit} \
+ -match glob \
+ -body {
+ list [catch {testexprlongobj 0x100000000} result] $result
+ } \
+ -result {1 {integer value too large to represent*}}
+test expr-39.8 {Tcl_ExprLongObj handles overflows} testexprlongobj {
+ testexprlongobj -0x80000000
+} {This is a result: -2147483648}
+test expr-39.9 {Tcl_ExprLongObj handles overflows} {testexprlongobj longIs32bit} {
+ testexprlongobj -0xffffffff
+} {This is a result: 1}
+test expr-39.10 {Tcl_ExprLongObj handles overflows} \
+ -constraints {testexprlongobj longIs32bit} \
+ -match glob \
+ -body {
+ list [catch {testexprlongobj -0x100000000} result] $result
+ } \
+ -result {1 {integer value too large to represent*}}
+test expr-39.11 {Tcl_ExprLongObj handles overflows} {testexprlongobj longIs32bit} {
+ testexprlongobj 2147483648.
+} {This is a result: -2147483648}
+test expr-39.12 {Tcl_ExprLongObj handles overflows} {testexprlongobj longIs32bit} {
+ testexprlongobj 4294967295.
+} {This is a result: -1}
+test expr-39.13 {Tcl_ExprLongObj handles overflows} \
+ -constraints {testexprlongobj longIs32bit} \
+ -match glob \
+ -body {
+ list [catch {testexprlongobj 4294967296.} result] $result
+ } \
+ -result {1 {integer value too large to represent*}}
+test expr-39.14 {Tcl_ExprLongObj handles overflows} testexprlongobj {
+ testexprlongobj -2147483648.
+} {This is a result: -2147483648}
+test expr-39.15 {Tcl_ExprLongObj handles overflows} {testexprlongobj longIs32bit} {
+ testexprlongobj -4294967295.
+} {This is a result: 1}
+test expr-39.16 {Tcl_ExprLongObj handles overflows} \
+ -constraints {testexprlongobj longIs32bit} \
+ -match glob \
+ -body {
+ list [catch {testexprlongobj 4294967296.} result] $result
+ } \
+ -result {1 {integer value too large to represent*}}
+
+test expr-39.17 {Check that Tcl_ExprDoubleObj doesn't modify interpreter result if no error} testexprdoubleobj {
+ testexprdoubleobj 4.+1.
+} {This is a result: 5.0}
+#Check for [Bug 1109484]
+test expr-39.18 {Tcl_ExprDoubleObj on the empty string} \
+ -constraints {testexprdoubleobj} \
+ -match glob \
+ -body {testexprdoubleobj ""} \
+ -returnCodes error -result *
+test expr-39.19 {Tcl_ExprDoubleObj coerces wides} testexprdoubleobj {
+ testexprdoubleobj 1[string repeat 0 17]
+} {This is a result: 1e+17}
+test expr-39.20 {Tcl_ExprDoubleObj coerces bignums} testexprdoubleobj {
+ testexprdoubleobj 1[string repeat 0 38]
+} {This is a result: 1e+38}
+test expr-39.21 {Tcl_ExprDoubleObj handles overflows} \
+ testexprdoubleobj&&ieeeFloatingPoint {
+ testexprdoubleobj 17976931348623157[string repeat 0 292].
+ } {This is a result: 1.7976931348623157e+308}
+test expr-39.22 {Tcl_ExprDoubleObj handles overflows that look like int} \
+ testexprdoubleobj&&ieeeFloatingPoint {
+ testexprdoubleobj 17976931348623157[string repeat 0 292]
+ } {This is a result: 1.7976931348623157e+308}
+test expr-39.23 {Tcl_ExprDoubleObj handles overflows} \
+ testexprdoubleobj&&ieeeFloatingPoint {
+ testexprdoubleobj 17976931348623165[string repeat 0 292].
+ } {This is a result: Inf}
+test expr-39.24 {Tcl_ExprDoubleObj handles overflows that look like int} \
+ testexprdoubleobj&&ieeeFloatingPoint {
+ testexprdoubleobj 17976931348623165[string repeat 0 292]
+ } {This is a result: Inf}
+test expr-39.25 {Tcl_ExprDoubleObj and NaN} \
+ {testexprdoubleobj ieeeFloatingPoint} {
+ list [catch {testexprdoubleobj 0.0/0.0} result] $result
+ } {1 {domain error: argument not in valid range}}
+
+test expr-40.1 {large octal shift} {
+ expr 0o100000000000000000000000000000000
+} [expr 0x1000000000000000000000000]
+test expr-40.2 {large octal shift} {
+ expr 0o100000000000000000000000000000001
+} [expr 0x1000000000000000000000001]
+
+test expr-41.1 {exponent overflow} {
+ expr 1.0e2147483630
+} Inf
+test expr-41.2 {exponent underflow} {
+ expr 1.0e-2147483630
+} 0.0
+
+test expr-42.1 {denormals} ieeeFloatingPoint {
+ expr 7e-324
+} 5e-324
+
+# TIP 114
+
+test expr-43.1 {0b notation} {
+ expr 0b0
+} 0
+test expr-43.2 {0b notation} {
+ expr 0b1
+} 1
+test expr-43.3 {0b notation} {
+ expr 0b10
+} 2
+test expr-43.4 {0b notation} {
+ expr 0b11
+} 3
+test expr-43.5 {0b notation} {
+ expr 0b100
+} 4
+test expr-43.6 {0b notation} {
+ expr 0b101
+} 5
+test expr-43.7 {0b notation} {
+ expr 0b1000
+} 8
+test expr-43.8 {0b notation} {
+ expr 0b1001
+} 9
+test expr-43.9 {0b notation} {
+ expr 0b1[string repeat 0 31]
+} 2147483648
+test expr-43.10 {0b notation} {
+ expr 0b1[string repeat 0 30]1
+} 2147483649
+test expr-43.11 {0b notation} {
+ expr 0b[string repeat 1 64]
+} 18446744073709551615
+test expr-43.12 {0b notation} {
+ expr 0b1[string repeat 0 64]
+} 18446744073709551616
+test expr-43.13 {0b notation} {
+ expr 0b1[string repeat 0 63]1
+} 18446744073709551617
+
+test expr-44.1 {0o notation} {
+ expr 0o0
+} 0
+test expr-44.2 {0o notation} {
+ expr 0o1
+} 1
+test expr-44.3 {0o notation} {
+ expr 0o7
+} 7
+test expr-44.4 {0o notation} {
+ expr 0o10
+} 8
+test expr-44.5 {0o notation} {
+ expr 0o11
+} 9
+test expr-44.6 {0o notation} {
+ expr 0o100
+} 64
+test expr-44.7 {0o notation} {
+ expr 0o101
+} 65
+test expr-44.8 {0o notation} {
+ expr 0o1000
+} 512
+test expr-44.9 {0o notation} {
+ expr 0o1001
+} 513
+test expr-44.10 {0o notation} {
+ expr 0o1[string repeat 7 21]
+} 18446744073709551615
+test expr-44.11 {0o notation} {
+ expr 0o2[string repeat 0 21]
+} 18446744073709551616
+test expr-44.12 {0o notation} {
+ expr 0o2[string repeat 0 20]1
+} 18446744073709551617
+
+# TIP 237 again
+
+test expr-45.1 {entier} {
+ expr entier(0)
+} 0
+test expr-45.2 {entier} {
+ expr entier(0.5)
+} 0
+test expr-45.3 {entier} {
+ expr entier(1.0)
+} 1
+test expr-45.4 {entier} {
+ expr entier(1.5)
+} 1
+test expr-45.5 {entier} {
+ expr entier(2.0)
+} 2
+test expr-45.6 {entier} {
+ expr entier(1e+22)
+} 10000000000000000000000
+test expr-45.7 {entier} {
+ list [catch {expr entier(Inf)} result] $result
+} {1 {integer value too large to represent}}
+test expr-45.8 {entier} ieeeFloatingPoint {
+ list [catch {expr {entier($ieeeValues(NaN))}} result] $result
+} {1 {floating point value is Not a Number}}
+test expr-45.9 {entier} ieeeFloatingPoint {
+ list [catch {expr {entier($ieeeValues(-NaN))}} result] $result
+} {1 {floating point value is Not a Number}}
test expr-46.1 {round() rounds to +-infinity} {
expr round(0.5)
@@ -6252,15 +6953,15 @@ test expr-46.4 {round() rounds to +-infinity} {
expr round(-1.5)
} -2
test expr-46.5 {round() overflow} {
- list [catch {expr round(9.2233720368547758e+018)} result] $result
-} {1 {integer value too large to represent}}
+ expr round(9.2233720368547758e+018)
+} 9223372036854775808
test expr-46.6 {round() overflow} {
- list [catch {expr round(-9.2233720368547758e+018)} result] $result
-} {1 {integer value too large to represent}}
-test expr-46.7 {round() bad value} {
+ expr round(-9.2233720368547758e+018)
+} -9223372036854775808
+test expr-46.7 {round() bad value} -body {
set x trash
- list [catch {expr {round($x)}} result] $result
-} {1 {argument to math function didn't have numeric value}}
+ expr {round($x)}
+} -returnCodes error -match glob -result *
test expr-46.8 {round() already an integer} {
set x 123456789012
incr x
@@ -6310,6 +7011,170 @@ test expr-46.12 {round() boundary case - -1/2 + 1 ulp} {
}
expr {round($x)}
} 0
+test expr-46.13 {round() boundary case - round down} {
+ expr {round(2147483647 - 0.51)}
+} 2147483646
+
+test expr-46.14 {round() boundary case - round up} {
+ expr {round(2147483647 - 0.50)}
+} 2147483647
+
+test expr-46.15 {round() boundary case - round up to wide} {
+ expr {round(2147483647 + 0.50)}
+} [expr {wide(2147483647) + 1}]
+
+test expr-46.16 {round() boundary case - round up} {
+ expr {round(-2147483648 + 0.51)}
+} -2147483647
+
+test expr-46.17 {round() boundary case - round down} {
+ expr {round(-2147483648 + 0.50)}
+} -2147483648
+test expr-46.18 {round() boundary case - round down to wide} {
+ expr {round(-2147483648 - 0.50)}
+} [expr {wide(-2147483648) - 1}]
+
+test expr-46.19 {round() handling of long/bignum boundary} {
+ expr {round(double(0x7fffffffffffffff))}
+} 9223372036854775808
+
+test expr-47.1 {isqrt() - arg count} {
+ list [catch {expr {isqrt(1,2)}} result] $result
+} {1 {too many arguments for math function "isqrt"}}
+
+test expr-47.2 {isqrt() - non-number} {
+ list [catch {expr {isqrt({rubbish})}} result] $result
+} {1 {expected number but got "rubbish"}}
+
+test expr-47.3 {isqrt() - NaN} ieeeFloatingPoint {
+ list [catch {expr {isqrt(NaN)}} result] $result
+} {1 {floating point value is Not a Number}}
+
+test expr-47.4 {isqrt() of negative floating point number} {
+ list [catch {expr {isqrt(-1.0)}} result] $result
+} {1 {square root of negative argument}}
+
+test expr-47.5 {isqrt() of floating point zero} {
+ expr isqrt(0.0)
+} 0
+
+test expr-47.6 {isqrt() of exact floating point numbers} {
+ set trouble {}
+ for {set i 0} {$i < 16} {incr i} {
+ set root [expr {1 << $i}]
+ set rm1 [expr {$root - 1}]
+ set arg [expr {pow(2., (2 * $i))}]
+ if {isqrt($arg-1) != $rm1} {
+ append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n"
+ }
+ if {isqrt($arg) != $root} {
+ append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n"
+ }
+ if {isqrt($arg+1) != $root} {
+ append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n"
+ }
+ }
+ set trouble
+} {}
+
+test expr-47.7 {isqrt() of exact floating point numbers} ieeeFloatingPoint {
+ set trouble {}
+ for {set i 17} {$i < 27} {incr i} {
+ set root [expr {1 << $i}]
+ set rm1 [expr {$root - 1}]
+ set arg [expr {pow(2., (2 * $i))}]
+ if {isqrt($arg-1.0) != $rm1} {
+ append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n"
+ }
+ if {isqrt($arg) != $root} {
+ append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n"
+ }
+ if {isqrt($arg+1.0) != $root} {
+ append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n"
+ }
+ }
+ set trouble
+} {}
+
+test expr-47.8 {isqrt of inexact floating point number} ieeeFloatingPoint {
+ expr isqrt(2[string repeat 0 34])
+} 141421356237309504
+
+test expr-47.9 {isqrt of negative int} {
+ list [catch {expr isqrt(-1)} result] $result
+} {1 {square root of negative argument}}
+
+test expr-47.10 {isqrt of negative bignum} {
+ list [catch {expr isqrt(-1[string repeat 0 1000])} result] $result
+} {1 {square root of negative argument}}
+
+test expr-47.11 {isqrt of zero} {
+ expr {isqrt(0)}
+} 0
+
+test expr-47.12 {isqrt of various sizes of integer} {
+ set faults 0
+ set trouble {}
+ for {set i 0} {$faults < 10 && $i <= 1024} {incr i} {
+ set root [expr {1 << $i}]
+ set rm1 [expr {$root - 1}]
+ set arg [expr {1 << (2 * $i)}]
+ set tval [expr {isqrt($arg-1)}]
+ if {$tval != $rm1} {
+ append trouble "i = " $i ": isqrt(" $arg "-1) == " $tval \
+ " != " $rm1 "\n"
+ incr faults
+ }
+ set tval [expr {isqrt($arg)}]
+ if {$tval != $root} {
+ append trouble "i = " $i ": isqrt(" $arg ") == " $tval \
+ " != " $root "\n"
+ incr faults
+ }
+ set tval [expr {isqrt($arg+1)}]
+ if {$tval != $root} {
+ append trouble "i = " $i ": isqrt(" $arg "+1) == " $tval \
+ " != " $root "\n"
+ incr faults
+ }
+ }
+ set trouble
+} {}
+
+test expr-47.13 {isqrt and floating point rounding (Bug 2143288)} {
+ set trouble {}
+ set faults 0
+ for {set i 0} {$i < 29 && $faults < 10} {incr i} {
+ for {set j 0} {$j <= $i} {incr j} {
+ set k [expr {isqrt((1<<56)+(1<<$i)+(1<<$j))}]
+ if {$k != (1<<28)} {
+ append trouble "i = $i, j = $j, k = $k\n"
+ incr faults
+ }
+ }
+ set k [expr {isqrt((1<<56)+(1<<29)+(1<<$i))}]
+ if {$k != (1<<28)+1} {
+ append trouble "i = $i, k = $k\n"
+ incr faults
+ }
+ }
+ set trouble
+} {}
+
+test expr-48.1 {Bug 1770224} {
+ expr {-0x8000000000000001 >> 0x8000000000000000}
+} -1
+
+test expr-49.1 {Bug 2823282} {
+ coroutine foo apply {{} {set expr expr; $expr {[yield]}}}
+ foo 1
+} 1
+
+test expr-50.1 {test sqrt() of bignums with non-Inf answer} {
+ expr {sqrt("1[string repeat 0 616]") == 1e308}
+} 1
+
+
# cleanup
if {[info exists a]} {