1 | # Commands covered: expr |
---|
2 | # |
---|
3 | # This file contains the original set of tests for Tcl's expr command. |
---|
4 | # Since the expr command is now compiled, a new set of tests covering |
---|
5 | # the new implementation are in the files "parseExpr.test" and |
---|
6 | # "compExpr.test". Sourcing this file into Tcl runs the tests and generates |
---|
7 | # output for errors. No output means no errors were found. |
---|
8 | # |
---|
9 | # Copyright (c) 1991-1994 The Regents of the University of California. |
---|
10 | # Copyright (c) 1994-1997 Sun Microsystems, Inc. |
---|
11 | # Copyright (c) 1998-2000 by Scriptics Corporation. |
---|
12 | # |
---|
13 | # See the file "license.terms" for information on usage and redistribution |
---|
14 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
15 | # |
---|
16 | # RCS: @(#) $Id: expr-old.test,v 1.40 2007/12/13 15:26:06 dgp Exp $ |
---|
17 | |
---|
18 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
19 | package require tcltest 2.1 |
---|
20 | namespace import -force ::tcltest::* |
---|
21 | } |
---|
22 | |
---|
23 | testConstraint testexprlong [llength [info commands testexprlong]] |
---|
24 | testConstraint testexprdouble [llength [info commands testexprdouble]] |
---|
25 | testConstraint testexprstring [llength [info commands testexprstring]] |
---|
26 | testConstraint longIs32bit [expr {int(0x80000000) < 0}] |
---|
27 | |
---|
28 | if {[catch {expr T1()} msg] && $msg eq {invalid command name "tcl::mathfunc::T1"}} { |
---|
29 | testConstraint testmathfunctions 0 |
---|
30 | } else { |
---|
31 | testConstraint testmathfunctions 1 |
---|
32 | } |
---|
33 | |
---|
34 | # Big test for correct ordering of data in [expr] |
---|
35 | |
---|
36 | proc testIEEE {} { |
---|
37 | variable ieeeValues |
---|
38 | binary scan [binary format dd -1.0 1.0] c* c |
---|
39 | switch -exact -- $c { |
---|
40 | {0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} { |
---|
41 | # little endian |
---|
42 | binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \ |
---|
43 | ieeeValues(-Infinity) |
---|
44 | binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \ |
---|
45 | ieeeValues(-Normal) |
---|
46 | binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \ |
---|
47 | ieeeValues(-Subnormal) |
---|
48 | binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \ |
---|
49 | ieeeValues(-0) |
---|
50 | binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \ |
---|
51 | ieeeValues(+0) |
---|
52 | binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \ |
---|
53 | ieeeValues(+Subnormal) |
---|
54 | binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \ |
---|
55 | ieeeValues(+Normal) |
---|
56 | binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \ |
---|
57 | ieeeValues(+Infinity) |
---|
58 | binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \ |
---|
59 | ieeeValues(NaN) |
---|
60 | set ieeeValues(littleEndian) 1 |
---|
61 | return 1 |
---|
62 | } |
---|
63 | {-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} { |
---|
64 | binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \ |
---|
65 | ieeeValues(-Infinity) |
---|
66 | binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \ |
---|
67 | ieeeValues(-Normal) |
---|
68 | binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \ |
---|
69 | ieeeValues(-Subnormal) |
---|
70 | binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \ |
---|
71 | ieeeValues(-0) |
---|
72 | binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \ |
---|
73 | ieeeValues(+0) |
---|
74 | binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \ |
---|
75 | ieeeValues(+Subnormal) |
---|
76 | binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \ |
---|
77 | ieeeValues(+Normal) |
---|
78 | binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \ |
---|
79 | ieeeValues(+Infinity) |
---|
80 | binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \ |
---|
81 | ieeeValues(NaN) |
---|
82 | set ieeeValues(littleEndian) 0 |
---|
83 | return 1 |
---|
84 | } |
---|
85 | default { |
---|
86 | return 0 |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | testConstraint ieeeFloatingPoint [testIEEE] |
---|
91 | |
---|
92 | # First, test all of the integer operators individually. |
---|
93 | |
---|
94 | test expr-old-1.1 {integer operators} {expr -4} -4 |
---|
95 | test expr-old-1.2 {integer operators} {expr -(1+4)} -5 |
---|
96 | test expr-old-1.3 {integer operators} {expr ~3} -4 |
---|
97 | test expr-old-1.4 {integer operators} {expr !2} 0 |
---|
98 | test expr-old-1.5 {integer operators} {expr !0} 1 |
---|
99 | test expr-old-1.6 {integer operators} {expr 4*6} 24 |
---|
100 | test expr-old-1.7 {integer operators} {expr 36/12} 3 |
---|
101 | test expr-old-1.8 {integer operators} {expr 27/4} 6 |
---|
102 | test expr-old-1.9 {integer operators} {expr 27%4} 3 |
---|
103 | test expr-old-1.10 {integer operators} {expr 2+2} 4 |
---|
104 | test expr-old-1.11 {integer operators} {expr 2-6} -4 |
---|
105 | test expr-old-1.12 {integer operators} {expr 1<<3} 8 |
---|
106 | test expr-old-1.13 {integer operators} {expr 0xff>>2} 63 |
---|
107 | test expr-old-1.14 {integer operators} {expr -1>>2} -1 |
---|
108 | test expr-old-1.15 {integer operators} {expr 3>2} 1 |
---|
109 | test expr-old-1.16 {integer operators} {expr 2>2} 0 |
---|
110 | test expr-old-1.17 {integer operators} {expr 1>2} 0 |
---|
111 | test expr-old-1.18 {integer operators} {expr 3<2} 0 |
---|
112 | test expr-old-1.19 {integer operators} {expr 2<2} 0 |
---|
113 | test expr-old-1.20 {integer operators} {expr 1<2} 1 |
---|
114 | test expr-old-1.21 {integer operators} {expr 3>=2} 1 |
---|
115 | test expr-old-1.22 {integer operators} {expr 2>=2} 1 |
---|
116 | test expr-old-1.23 {integer operators} {expr 1>=2} 0 |
---|
117 | test expr-old-1.24 {integer operators} {expr 3<=2} 0 |
---|
118 | test expr-old-1.25 {integer operators} {expr 2<=2} 1 |
---|
119 | test expr-old-1.26 {integer operators} {expr 1<=2} 1 |
---|
120 | test expr-old-1.27 {integer operators} {expr 3==2} 0 |
---|
121 | test expr-old-1.28 {integer operators} {expr 2==2} 1 |
---|
122 | test expr-old-1.29 {integer operators} {expr 3!=2} 1 |
---|
123 | test expr-old-1.30 {integer operators} {expr 2!=2} 0 |
---|
124 | test expr-old-1.31 {integer operators} {expr 7&0x13} 3 |
---|
125 | test expr-old-1.32 {integer operators} {expr 7^0x13} 20 |
---|
126 | test expr-old-1.33 {integer operators} {expr 7|0x13} 23 |
---|
127 | test expr-old-1.34 {integer operators} {expr 0&&1} 0 |
---|
128 | test expr-old-1.35 {integer operators} {expr 0&&0} 0 |
---|
129 | test expr-old-1.36 {integer operators} {expr 1&&3} 1 |
---|
130 | test expr-old-1.37 {integer operators} {expr 0||1} 1 |
---|
131 | test expr-old-1.38 {integer operators} {expr 3||0} 1 |
---|
132 | test expr-old-1.39 {integer operators} {expr 0||0} 0 |
---|
133 | test expr-old-1.40 {integer operators} {expr 3>2?44:66} 44 |
---|
134 | test expr-old-1.41 {integer operators} {expr 2>3?44:66} 66 |
---|
135 | test expr-old-1.42 {integer operators} {expr 36/5} 7 |
---|
136 | test expr-old-1.43 {integer operators} {expr 36%5} 1 |
---|
137 | test expr-old-1.44 {integer operators} {expr -36/5} -8 |
---|
138 | test expr-old-1.45 {integer operators} {expr -36%5} 4 |
---|
139 | test expr-old-1.46 {integer operators} {expr 36/-5} -8 |
---|
140 | test expr-old-1.47 {integer operators} {expr 36%-5} -4 |
---|
141 | test expr-old-1.48 {integer operators} {expr -36/-5} 7 |
---|
142 | test expr-old-1.49 {integer operators} {expr -36%-5} -1 |
---|
143 | test expr-old-1.50 {integer operators} {expr +36} 36 |
---|
144 | test expr-old-1.51 {integer operators} {expr +--++36} 36 |
---|
145 | test expr-old-1.52 {integer operators} {expr +36%+5} 1 |
---|
146 | test expr-old-1.53 {integer operators} { |
---|
147 | catch {unset x} |
---|
148 | set x yes |
---|
149 | list [expr {1 && $x}] [expr {$x && 1}] \ |
---|
150 | [expr {0 || $x}] [expr {$x || 0}] |
---|
151 | } {1 1 1 1} |
---|
152 | |
---|
153 | # Check the floating-point operators individually, along with |
---|
154 | # automatic conversion to integers where needed. |
---|
155 | |
---|
156 | test expr-old-2.1 {floating-point operators} {expr -4.2} -4.2 |
---|
157 | test expr-old-2.2 {floating-point operators} {expr -(1.125+4.25)} -5.375 |
---|
158 | test expr-old-2.3 {floating-point operators} {expr +5.7} 5.7 |
---|
159 | test expr-old-2.4 {floating-point operators} {expr +--+-62.0} -62.0 |
---|
160 | test expr-old-2.5 {floating-point operators} {expr !2.1} 0 |
---|
161 | test expr-old-2.6 {floating-point operators} {expr !0.0} 1 |
---|
162 | test expr-old-2.7 {floating-point operators} {expr 4.2*6.3} 26.46 |
---|
163 | test expr-old-2.8 {floating-point operators} {expr 36.0/12.0} 3.0 |
---|
164 | test expr-old-2.9 {floating-point operators} {expr 27/4.0} 6.75 |
---|
165 | test expr-old-2.10 {floating-point operators} {expr 2.3+2.1} 4.4 |
---|
166 | test expr-old-2.11 {floating-point operators} {expr 2.3-6.5} -4.2 |
---|
167 | test expr-old-2.12 {floating-point operators} {expr 3.1>2.1} 1 |
---|
168 | test expr-old-2.13 {floating-point operators} {expr {2.1 > 2.1}} 0 |
---|
169 | test expr-old-2.14 {floating-point operators} {expr 1.23>2.34e+1} 0 |
---|
170 | test expr-old-2.15 {floating-point operators} {expr 3.45<2.34} 0 |
---|
171 | test expr-old-2.16 {floating-point operators} {expr 0.002e3<--200e-2} 0 |
---|
172 | test expr-old-2.17 {floating-point operators} {expr 1.1<2.1} 1 |
---|
173 | test expr-old-2.18 {floating-point operators} {expr 3.1>=2.2} 1 |
---|
174 | test expr-old-2.19 {floating-point operators} {expr 2.345>=2.345} 1 |
---|
175 | test expr-old-2.20 {floating-point operators} {expr 1.1>=2.2} 0 |
---|
176 | test expr-old-2.21 {floating-point operators} {expr 3.0<=2.0} 0 |
---|
177 | test expr-old-2.22 {floating-point operators} {expr 2.2<=2.2} 1 |
---|
178 | test expr-old-2.23 {floating-point operators} {expr 2.2<=2.2001} 1 |
---|
179 | test expr-old-2.24 {floating-point operators} {expr 3.2==2.2} 0 |
---|
180 | test expr-old-2.25 {floating-point operators} {expr 2.2==2.2} 1 |
---|
181 | test expr-old-2.26 {floating-point operators} {expr 3.2!=2.2} 1 |
---|
182 | test expr-old-2.27 {floating-point operators} {expr 2.2!=2.2} 0 |
---|
183 | test expr-old-2.28 {floating-point operators} {expr 0.0&&0.0} 0 |
---|
184 | test expr-old-2.29 {floating-point operators} {expr 0.0&&1.3} 0 |
---|
185 | test expr-old-2.30 {floating-point operators} {expr 1.3&&0.0} 0 |
---|
186 | test expr-old-2.31 {floating-point operators} {expr 1.3&&3.3} 1 |
---|
187 | test expr-old-2.32 {floating-point operators} {expr 0.0||0.0} 0 |
---|
188 | test expr-old-2.33 {floating-point operators} {expr 0.0||1.3} 1 |
---|
189 | test expr-old-2.34 {floating-point operators} {expr 1.3||0.0} 1 |
---|
190 | test expr-old-2.35 {floating-point operators} {expr 3.3||0.0} 1 |
---|
191 | test expr-old-2.36 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3 |
---|
192 | test expr-old-2.37 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3 |
---|
193 | test expr-old-2.38 {floating-point operators} { |
---|
194 | list [catch {expr 028.1 + 09.2} msg] $msg |
---|
195 | } {0 37.3} |
---|
196 | |
---|
197 | # Operators that aren't legal on floating-point numbers |
---|
198 | |
---|
199 | test expr-old-3.1 {illegal floating-point operations} { |
---|
200 | list [catch {expr ~4.0} msg] $msg |
---|
201 | } {1 {can't use floating-point value as operand of "~"}} |
---|
202 | test expr-old-3.2 {illegal floating-point operations} { |
---|
203 | list [catch {expr 27%4.0} msg] $msg |
---|
204 | } {1 {can't use floating-point value as operand of "%"}} |
---|
205 | test expr-old-3.3 {illegal floating-point operations} { |
---|
206 | list [catch {expr 27.0%4} msg] $msg |
---|
207 | } {1 {can't use floating-point value as operand of "%"}} |
---|
208 | test expr-old-3.4 {illegal floating-point operations} { |
---|
209 | list [catch {expr 1.0<<3} msg] $msg |
---|
210 | } {1 {can't use floating-point value as operand of "<<"}} |
---|
211 | test expr-old-3.5 {illegal floating-point operations} { |
---|
212 | list [catch {expr 3<<1.0} msg] $msg |
---|
213 | } {1 {can't use floating-point value as operand of "<<"}} |
---|
214 | test expr-old-3.6 {illegal floating-point operations} { |
---|
215 | list [catch {expr 24.0>>3} msg] $msg |
---|
216 | } {1 {can't use floating-point value as operand of ">>"}} |
---|
217 | test expr-old-3.7 {illegal floating-point operations} { |
---|
218 | list [catch {expr 24>>3.0} msg] $msg |
---|
219 | } {1 {can't use floating-point value as operand of ">>"}} |
---|
220 | test expr-old-3.8 {illegal floating-point operations} { |
---|
221 | list [catch {expr 24&3.0} msg] $msg |
---|
222 | } {1 {can't use floating-point value as operand of "&"}} |
---|
223 | test expr-old-3.9 {illegal floating-point operations} { |
---|
224 | list [catch {expr 24.0|3} msg] $msg |
---|
225 | } {1 {can't use floating-point value as operand of "|"}} |
---|
226 | test expr-old-3.10 {illegal floating-point operations} { |
---|
227 | list [catch {expr 24.0^3} msg] $msg |
---|
228 | } {1 {can't use floating-point value as operand of "^"}} |
---|
229 | |
---|
230 | # Check the string operators individually. |
---|
231 | |
---|
232 | test expr-old-4.1 {string operators} {expr {"abc" > "def"}} 0 |
---|
233 | test expr-old-4.2 {string operators} {expr {"def" > "def"}} 0 |
---|
234 | test expr-old-4.3 {string operators} {expr {"g" > "def"}} 1 |
---|
235 | test expr-old-4.4 {string operators} {expr {"abc" < "abd"}} 1 |
---|
236 | test expr-old-4.5 {string operators} {expr {"abd" < "abd"}} 0 |
---|
237 | test expr-old-4.6 {string operators} {expr {"abe" < "abd"}} 0 |
---|
238 | test expr-old-4.7 {string operators} {expr {"abc" >= "def"}} 0 |
---|
239 | test expr-old-4.8 {string operators} {expr {"def" >= "def"}} 1 |
---|
240 | test expr-old-4.9 {string operators} {expr {"g" >= "def"}} 1 |
---|
241 | test expr-old-4.10 {string operators} {expr {"abc" <= "abd"}} 1 |
---|
242 | test expr-old-4.11 {string operators} {expr {"abd" <= "abd"}} 1 |
---|
243 | test expr-old-4.12 {string operators} {expr {"abe" <= "abd"}} 0 |
---|
244 | test expr-old-4.13 {string operators} {expr {"abc" == "abd"}} 0 |
---|
245 | test expr-old-4.14 {string operators} {expr {"abd" == "abd"}} 1 |
---|
246 | test expr-old-4.15 {string operators} {expr {"abc" != "abd"}} 1 |
---|
247 | test expr-old-4.16 {string operators} {expr {"abd" != "abd"}} 0 |
---|
248 | test expr-old-4.17 {string operators} {expr {"0y" < "0x12"}} 0 |
---|
249 | test expr-old-4.18 {string operators} {expr {"." < " "}} 0 |
---|
250 | test expr-old-4.19 {string operators} {expr {"abc" eq "abd"}} 0 |
---|
251 | test expr-old-4.20 {string operators} {expr {"abd" eq "abd"}} 1 |
---|
252 | test expr-old-4.21 {string operators} {expr {"abc" ne "abd"}} 1 |
---|
253 | test expr-old-4.22 {string operators} {expr {"abd" ne "abd"}} 0 |
---|
254 | test expr-old-4.23 {string operators} {expr {"" eq "abd"}} 0 |
---|
255 | test expr-old-4.24 {string operators} {expr {"" eq ""}} 1 |
---|
256 | test expr-old-4.25 {string operators} {expr {"abd" ne ""}} 1 |
---|
257 | test expr-old-4.26 {string operators} {expr {"" ne ""}} 0 |
---|
258 | test expr-old-4.27 {string operators} {expr {"longerstring" eq "shorter"}} 0 |
---|
259 | test expr-old-4.28 {string operators} {expr {"longerstring" ne "shorter"}} 1 |
---|
260 | test expr-old-4.29 {string operators} {expr {"0" == "+"}} 0 |
---|
261 | test expr-old-4.30 {string operators} {expr {"0" == "-"}} 0 |
---|
262 | test expr-old-4.31 {string operators} {expr {1?"foo":"bar"}} foo |
---|
263 | test expr-old-4.32 {string operators} {expr {0?"foo":"bar"}} bar |
---|
264 | |
---|
265 | # Operators that aren't legal on string operands. |
---|
266 | |
---|
267 | test expr-old-5.1 {illegal string operations} { |
---|
268 | list [catch {expr {-"a"}} msg] $msg |
---|
269 | } {1 {can't use non-numeric string as operand of "-"}} |
---|
270 | test expr-old-5.2 {illegal string operations} { |
---|
271 | list [catch {expr {+"a"}} msg] $msg |
---|
272 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
273 | test expr-old-5.3 {illegal string operations} { |
---|
274 | list [catch {expr {~"a"}} msg] $msg |
---|
275 | } {1 {can't use non-numeric string as operand of "~"}} |
---|
276 | test expr-old-5.4 {illegal string operations} { |
---|
277 | list [catch {expr {!"a"}} msg] $msg |
---|
278 | } {1 {can't use non-numeric string as operand of "!"}} |
---|
279 | test expr-old-5.5 {illegal string operations} { |
---|
280 | list [catch {expr {"a"*"b"}} msg] $msg |
---|
281 | } {1 {can't use non-numeric string as operand of "*"}} |
---|
282 | test expr-old-5.6 {illegal string operations} { |
---|
283 | list [catch {expr {"a"/"b"}} msg] $msg |
---|
284 | } {1 {can't use non-numeric string as operand of "/"}} |
---|
285 | test expr-old-5.7 {illegal string operations} { |
---|
286 | list [catch {expr {"a"%"b"}} msg] $msg |
---|
287 | } {1 {can't use non-numeric string as operand of "%"}} |
---|
288 | test expr-old-5.8 {illegal string operations} { |
---|
289 | list [catch {expr {"a"+"b"}} msg] $msg |
---|
290 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
291 | test expr-old-5.9 {illegal string operations} { |
---|
292 | list [catch {expr {"a"-"b"}} msg] $msg |
---|
293 | } {1 {can't use non-numeric string as operand of "-"}} |
---|
294 | test expr-old-5.10 {illegal string operations} { |
---|
295 | list [catch {expr {"a"<<"b"}} msg] $msg |
---|
296 | } {1 {can't use non-numeric string as operand of "<<"}} |
---|
297 | test expr-old-5.11 {illegal string operations} { |
---|
298 | list [catch {expr {"a">>"b"}} msg] $msg |
---|
299 | } {1 {can't use non-numeric string as operand of ">>"}} |
---|
300 | test expr-old-5.12 {illegal string operations} { |
---|
301 | list [catch {expr {"a"&"b"}} msg] $msg |
---|
302 | } {1 {can't use non-numeric string as operand of "&"}} |
---|
303 | test expr-old-5.13 {illegal string operations} { |
---|
304 | list [catch {expr {"a"^"b"}} msg] $msg |
---|
305 | } {1 {can't use non-numeric string as operand of "^"}} |
---|
306 | test expr-old-5.14 {illegal string operations} { |
---|
307 | list [catch {expr {"a"|"b"}} msg] $msg |
---|
308 | } {1 {can't use non-numeric string as operand of "|"}} |
---|
309 | test expr-old-5.15 {illegal string operations} { |
---|
310 | list [catch {expr {"a"&&"b"}} msg] $msg |
---|
311 | } {1 {expected boolean value but got "a"}} |
---|
312 | test expr-old-5.16 {illegal string operations} { |
---|
313 | list [catch {expr {"a"||"b"}} msg] $msg |
---|
314 | } {1 {expected boolean value but got "a"}} |
---|
315 | test expr-old-5.17 {illegal string operations} { |
---|
316 | list [catch {expr {"a"?4:2}} msg] $msg |
---|
317 | } {1 {expected boolean value but got "a"}} |
---|
318 | |
---|
319 | # Check precedence pairwise. |
---|
320 | |
---|
321 | test expr-old-6.1 {precedence checks} {expr -~3} 4 |
---|
322 | test expr-old-6.2 {precedence checks} {expr -!3} 0 |
---|
323 | test expr-old-6.3 {precedence checks} {expr -~0} 1 |
---|
324 | |
---|
325 | test expr-old-7.1 {precedence checks} {expr 2*4/6} 1 |
---|
326 | test expr-old-7.2 {precedence checks} {expr 24/6*3} 12 |
---|
327 | test expr-old-7.3 {precedence checks} {expr 24/6/2} 2 |
---|
328 | |
---|
329 | test expr-old-8.1 {precedence checks} {expr -2+4} 2 |
---|
330 | test expr-old-8.2 {precedence checks} {expr -2-4} -6 |
---|
331 | test expr-old-8.3 {precedence checks} {expr +2-4} -2 |
---|
332 | |
---|
333 | test expr-old-9.1 {precedence checks} {expr 2*3+4} 10 |
---|
334 | test expr-old-9.2 {precedence checks} {expr 8/2+4} 8 |
---|
335 | test expr-old-9.3 {precedence checks} {expr 8%3+4} 6 |
---|
336 | test expr-old-9.4 {precedence checks} {expr 2*3-1} 5 |
---|
337 | test expr-old-9.5 {precedence checks} {expr 8/2-1} 3 |
---|
338 | test expr-old-9.6 {precedence checks} {expr 8%3-1} 1 |
---|
339 | |
---|
340 | test expr-old-10.1 {precedence checks} {expr 6-3-2} 1 |
---|
341 | |
---|
342 | test expr-old-11.1 {precedence checks} {expr 7+1>>2} 2 |
---|
343 | test expr-old-11.2 {precedence checks} {expr 7+1<<2} 32 |
---|
344 | test expr-old-11.3 {precedence checks} {expr 7>>3-2} 3 |
---|
345 | test expr-old-11.4 {precedence checks} {expr 7<<3-2} 14 |
---|
346 | |
---|
347 | test expr-old-12.1 {precedence checks} {expr 6>>1>4} 0 |
---|
348 | test expr-old-12.2 {precedence checks} {expr 6>>1<2} 0 |
---|
349 | test expr-old-12.3 {precedence checks} {expr 6>>1>=3} 1 |
---|
350 | test expr-old-12.4 {precedence checks} {expr 6>>1<=2} 0 |
---|
351 | test expr-old-12.5 {precedence checks} {expr 6<<1>5} 1 |
---|
352 | test expr-old-12.6 {precedence checks} {expr 6<<1<5} 0 |
---|
353 | test expr-old-12.7 {precedence checks} {expr 5<=6<<1} 1 |
---|
354 | test expr-old-12.8 {precedence checks} {expr 5>=6<<1} 0 |
---|
355 | |
---|
356 | test expr-old-13.1 {precedence checks} {expr 2<3<4} 1 |
---|
357 | test expr-old-13.2 {precedence checks} {expr 0<4>2} 0 |
---|
358 | test expr-old-13.3 {precedence checks} {expr 4>2<1} 0 |
---|
359 | test expr-old-13.4 {precedence checks} {expr 4>3>2} 0 |
---|
360 | test expr-old-13.5 {precedence checks} {expr 4>3>=2} 0 |
---|
361 | test expr-old-13.6 {precedence checks} {expr 4>=3>2} 0 |
---|
362 | test expr-old-13.7 {precedence checks} {expr 4>=3>=2} 0 |
---|
363 | test expr-old-13.8 {precedence checks} {expr 0<=4>=2} 0 |
---|
364 | test expr-old-13.9 {precedence checks} {expr 4>=2<=0} 0 |
---|
365 | test expr-old-13.10 {precedence checks} {expr 2<=3<=4} 1 |
---|
366 | |
---|
367 | test expr-old-14.1 {precedence checks} {expr 1==4>3} 1 |
---|
368 | test expr-old-14.2 {precedence checks} {expr 0!=4>3} 1 |
---|
369 | test expr-old-14.3 {precedence checks} {expr 1==3<4} 1 |
---|
370 | test expr-old-14.4 {precedence checks} {expr 0!=3<4} 1 |
---|
371 | test expr-old-14.5 {precedence checks} {expr 1==4>=3} 1 |
---|
372 | test expr-old-14.6 {precedence checks} {expr 0!=4>=3} 1 |
---|
373 | test expr-old-14.7 {precedence checks} {expr 1==3<=4} 1 |
---|
374 | test expr-old-14.8 {precedence checks} {expr 0!=3<=4} 1 |
---|
375 | test expr-old-14.9 {precedence checks} {expr 1eq4>3} 1 |
---|
376 | test expr-old-14.10 {precedence checks} {expr 0ne4>3} 1 |
---|
377 | test expr-old-14.11 {precedence checks} {expr 1eq3<4} 1 |
---|
378 | test expr-old-14.12 {precedence checks} {expr 0ne3<4} 1 |
---|
379 | test expr-old-14.13 {precedence checks} {expr 1eq4>=3} 1 |
---|
380 | test expr-old-14.14 {precedence checks} {expr 0ne4>=3} 1 |
---|
381 | test expr-old-14.15 {precedence checks} {expr 1eq3<=4} 1 |
---|
382 | test expr-old-14.16 {precedence checks} {expr 0ne3<=4} 1 |
---|
383 | |
---|
384 | test expr-old-15.1 {precedence checks} {expr 1==3==3} 0 |
---|
385 | test expr-old-15.2 {precedence checks} {expr 3==3!=2} 1 |
---|
386 | test expr-old-15.3 {precedence checks} {expr 2!=3==3} 0 |
---|
387 | test expr-old-15.4 {precedence checks} {expr 2!=1!=1} 0 |
---|
388 | test expr-old-15.5 {precedence checks} {expr 1eq3eq3} 0 |
---|
389 | test expr-old-15.6 {precedence checks} {expr 3eq3ne2} 1 |
---|
390 | test expr-old-15.7 {precedence checks} {expr 2ne3eq3} 0 |
---|
391 | test expr-old-15.8 {precedence checks} {expr 2ne1ne1} 0 |
---|
392 | |
---|
393 | test expr-old-16.1 {precedence checks} {expr 2&3eq2} 0 |
---|
394 | test expr-old-16.2 {precedence checks} {expr 1&3ne3} 0 |
---|
395 | test expr-old-16.3 {precedence checks} {expr 2&3eq2} 0 |
---|
396 | test expr-old-16.4 {precedence checks} {expr 1&3ne3} 0 |
---|
397 | |
---|
398 | test expr-old-17.1 {precedence checks} {expr 7&3^0x10} 19 |
---|
399 | test expr-old-17.2 {precedence checks} {expr 7^0x10&3} 7 |
---|
400 | |
---|
401 | test expr-old-18.1 {precedence checks} {expr 7^0x10|3} 23 |
---|
402 | test expr-old-18.2 {precedence checks} {expr 7|0x10^3} 23 |
---|
403 | |
---|
404 | test expr-old-19.1 {precedence checks} {expr 7|3&&1} 1 |
---|
405 | test expr-old-19.2 {precedence checks} {expr 1&&3|7} 1 |
---|
406 | test expr-old-19.3 {precedence checks} {expr 0&&1||1} 1 |
---|
407 | test expr-old-19.4 {precedence checks} {expr 1||1&&0} 1 |
---|
408 | |
---|
409 | test expr-old-20.1 {precedence checks} {expr 1||0?3:4} 3 |
---|
410 | test expr-old-20.2 {precedence checks} {expr 1?0:4||1} 0 |
---|
411 | test expr-old-20.3 {precedence checks} {expr 1?2:0?3:4} 2 |
---|
412 | test expr-old-20.4 {precedence checks} {expr 0?2:0?3:4} 4 |
---|
413 | test expr-old-20.5 {precedence checks} {expr 1?2?3:4:0} 3 |
---|
414 | test expr-old-20.6 {precedence checks} {expr 0?2?3:4:0} 0 |
---|
415 | |
---|
416 | # Parentheses. |
---|
417 | |
---|
418 | test expr-old-21.1 {parenthesization} {expr (2+4)*6} 36 |
---|
419 | test expr-old-21.2 {parenthesization} {expr (1?0:4)||1} 1 |
---|
420 | test expr-old-21.3 {parenthesization} {expr +(3-4)} -1 |
---|
421 | |
---|
422 | # Embedded commands and variable names. |
---|
423 | |
---|
424 | set a 16 |
---|
425 | test expr-old-22.1 {embedded variables} {expr {2*$a}} 32 |
---|
426 | test expr-old-22.2 {embedded variables} { |
---|
427 | set x -5 |
---|
428 | set y 10 |
---|
429 | expr {$x + $y} |
---|
430 | } {5} |
---|
431 | test expr-old-22.3 {embedded variables} { |
---|
432 | set x " -5" |
---|
433 | set y " +10" |
---|
434 | expr {$x + $y} |
---|
435 | } {5} |
---|
436 | test expr-old-22.4 {embedded commands and variables} {expr {[set a] - 14}} 2 |
---|
437 | test expr-old-22.5 {embedded commands and variables} { |
---|
438 | list [catch {expr {12 - [bad_command_name]}} msg] $msg |
---|
439 | } {1 {invalid command name "bad_command_name"}} |
---|
440 | |
---|
441 | # Double-quotes and things inside them. |
---|
442 | |
---|
443 | test expr-old-23.1 {double quotes} {expr {"abc"}} abc |
---|
444 | test expr-old-23.2 {double quotes} { |
---|
445 | set a 189 |
---|
446 | expr {"$a.bc"} |
---|
447 | } 189.bc |
---|
448 | test expr-old-23.3 {double quotes} { |
---|
449 | set b2 xyx |
---|
450 | expr {"$b2$b2$b2.[set b2].[set b2]"} |
---|
451 | } xyxxyxxyx.xyx.xyx |
---|
452 | test expr-old-23.4 {double quotes} {expr {"11\}\}22"}} 11}}22 |
---|
453 | test expr-old-23.5 {double quotes} {expr {"\*bc"}} {*bc} |
---|
454 | test expr-old-23.6 {double quotes} { |
---|
455 | catch {unset bogus__} |
---|
456 | list [catch {expr {"$bogus__"}} msg] $msg |
---|
457 | } {1 {can't read "bogus__": no such variable}} |
---|
458 | test expr-old-23.7 {double quotes} { |
---|
459 | list [catch {expr {"a[error Testing]bc"}} msg] $msg |
---|
460 | } {1 Testing} |
---|
461 | test expr-old-23.8 {double quotes} { |
---|
462 | list [catch {expr {"12398712938788234-1298379" != ""}} msg] $msg |
---|
463 | } {0 1} |
---|
464 | |
---|
465 | # Numbers in various bases. |
---|
466 | |
---|
467 | test expr-old-24.1 {numbers in different bases} {expr 0x20} 32 |
---|
468 | test expr-old-24.2 {numbers in different bases} {expr 0o15} 13 |
---|
469 | |
---|
470 | # Conversions between various data types. |
---|
471 | |
---|
472 | test expr-old-25.1 {type conversions} {expr 2+2.5} 4.5 |
---|
473 | test expr-old-25.2 {type conversions} {expr 2.5+2} 4.5 |
---|
474 | test expr-old-25.3 {type conversions} {expr 2-2.5} -0.5 |
---|
475 | test expr-old-25.4 {type conversions} {expr 2/2.5} 0.8 |
---|
476 | test expr-old-25.5 {type conversions} {expr 2>2.5} 0 |
---|
477 | test expr-old-25.6 {type conversions} {expr 2.5>2} 1 |
---|
478 | test expr-old-25.7 {type conversions} {expr 2<2.5} 1 |
---|
479 | test expr-old-25.8 {type conversions} {expr 2>=2.5} 0 |
---|
480 | test expr-old-25.9 {type conversions} {expr 2<=2.5} 1 |
---|
481 | test expr-old-25.10 {type conversions} {expr 2==2.5} 0 |
---|
482 | test expr-old-25.11 {type conversions} {expr 2!=2.5} 1 |
---|
483 | test expr-old-25.12 {type conversions} {expr 2>"ab"} 0 |
---|
484 | test expr-old-25.13 {type conversions} {expr {2>" "}} 1 |
---|
485 | test expr-old-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1 |
---|
486 | test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0 |
---|
487 | test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5 |
---|
488 | test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5 |
---|
489 | test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0 |
---|
490 | test expr-old-25.19 {type conversions} {expr 2.0e15} 2000000000000000.0 |
---|
491 | test expr-old-25.20 {type conversions} {expr 10.0} 10.0 |
---|
492 | |
---|
493 | # Various error conditions. |
---|
494 | |
---|
495 | test expr-old-26.1 {error conditions} { |
---|
496 | list [catch {expr 2+"a"} msg] $msg |
---|
497 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
498 | test expr-old-26.2 {error conditions} -body { |
---|
499 | expr 2+4* |
---|
500 | } -returnCodes error -match glob -result * |
---|
501 | test expr-old-26.3 {error conditions} -body { |
---|
502 | expr 2+4*( |
---|
503 | } -returnCodes error -match glob -result * |
---|
504 | catch {unset _non_existent_} |
---|
505 | test expr-old-26.4 {error conditions} { |
---|
506 | list [catch {expr 2+$_non_existent_} msg] $msg |
---|
507 | } {1 {can't read "_non_existent_": no such variable}} |
---|
508 | set a xx |
---|
509 | test expr-old-26.5 {error conditions} { |
---|
510 | list [catch {expr {2+$a}} msg] $msg |
---|
511 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
512 | test expr-old-26.6 {error conditions} { |
---|
513 | list [catch {expr {2+[set a]}} msg] $msg |
---|
514 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
515 | test expr-old-26.7 {error conditions} -body { |
---|
516 | expr {2+(4} |
---|
517 | } -returnCodes error -match glob -result * |
---|
518 | test expr-old-26.8 {error conditions} { |
---|
519 | list [catch {expr 2/0} msg] $msg $errorCode |
---|
520 | } {1 {divide by zero} {ARITH DIVZERO {divide by zero}}} |
---|
521 | test expr-old-26.9 {error conditions} { |
---|
522 | list [catch {expr 2%0} msg] $msg $errorCode |
---|
523 | } {1 {divide by zero} {ARITH DIVZERO {divide by zero}}} |
---|
524 | test expr-old-26.10a {error conditions} !ieeeFloatingPoint { |
---|
525 | list [catch {expr 2.0/0.0} msg] $msg $errorCode |
---|
526 | } {1 {divide by zero} {ARITH DIVZERO {divide by zero}}} |
---|
527 | test expr-old-26.10b {error conditions} ieeeFloatingPoint { |
---|
528 | list [catch {expr 2.0/0.0} msg] $msg |
---|
529 | } {0 Inf} |
---|
530 | test expr-old-26.11 {error conditions} -body { |
---|
531 | expr 2# |
---|
532 | } -returnCodes error -match glob -result * |
---|
533 | test expr-old-26.12 {error conditions} -body { |
---|
534 | expr a.b |
---|
535 | } -returnCodes error -match glob -result * |
---|
536 | test expr-old-26.13 {error conditions} { |
---|
537 | list [catch {expr {"a"/"b"}} msg] $msg |
---|
538 | } {1 {can't use non-numeric string as operand of "/"}} |
---|
539 | test expr-old-26.14 {error conditions} -body { |
---|
540 | expr 2:3 |
---|
541 | } -returnCodes error -match glob -result * |
---|
542 | test expr-old-26.15 {error conditions} -body { |
---|
543 | expr a@b |
---|
544 | } -returnCodes error -match glob -result * |
---|
545 | test expr-old-26.16 {error conditions} { |
---|
546 | list [catch {expr a[b} msg] $msg |
---|
547 | } {1 {missing close-bracket}} |
---|
548 | test expr-old-26.17 {error conditions} -body { |
---|
549 | expr a`b |
---|
550 | } -returnCodes error -match glob -result * |
---|
551 | test expr-old-26.18 {error conditions} -body { |
---|
552 | expr \"a\"\{b |
---|
553 | } -returnCodes error -match glob -result * |
---|
554 | test expr-old-26.19 {error conditions} -body { |
---|
555 | expr a |
---|
556 | } -returnCodes error -match glob -result * |
---|
557 | test expr-old-26.20 {error conditions} { |
---|
558 | list [catch expr msg] $msg |
---|
559 | } {1 {wrong # args: should be "expr arg ?arg ...?"}} |
---|
560 | |
---|
561 | # Cancelled evaluation. |
---|
562 | |
---|
563 | test expr-old-27.1 {cancelled evaluation} { |
---|
564 | set a 1 |
---|
565 | expr {0&&[set a 2]} |
---|
566 | set a |
---|
567 | } 1 |
---|
568 | test expr-old-27.2 {cancelled evaluation} { |
---|
569 | set a 1 |
---|
570 | expr {1||[set a 2]} |
---|
571 | set a |
---|
572 | } 1 |
---|
573 | test expr-old-27.3 {cancelled evaluation} { |
---|
574 | set a 1 |
---|
575 | expr {0?[set a 2]:1} |
---|
576 | set a |
---|
577 | } 1 |
---|
578 | test expr-old-27.4 {cancelled evaluation} { |
---|
579 | set a 1 |
---|
580 | expr {1?2:[set a 2]} |
---|
581 | set a |
---|
582 | } 1 |
---|
583 | catch {unset x} |
---|
584 | test expr-old-27.5 {cancelled evaluation} { |
---|
585 | list [catch {expr {[info exists x] && $x}} msg] $msg |
---|
586 | } {0 0} |
---|
587 | test expr-old-27.6 {cancelled evaluation} { |
---|
588 | list [catch {expr {0 && [concat $x]}} msg] $msg |
---|
589 | } {0 0} |
---|
590 | test expr-old-27.7 {cancelled evaluation} { |
---|
591 | set one 1 |
---|
592 | list [catch {expr {1 || 1/$one}} msg] $msg |
---|
593 | } {0 1} |
---|
594 | test expr-old-27.8 {cancelled evaluation} { |
---|
595 | list [catch {expr {1 || -"string"}} msg] $msg |
---|
596 | } {0 1} |
---|
597 | test expr-old-27.9 {cancelled evaluation} { |
---|
598 | list [catch {expr {1 || ("string" * ("x" && "y"))}} msg] $msg |
---|
599 | } {0 1} |
---|
600 | test expr-old-27.10 {cancelled evaluation} { |
---|
601 | set x -1.0 |
---|
602 | list [catch {expr {($x > 0) ? round(log($x)) : 0}} msg] $msg |
---|
603 | } {0 0} |
---|
604 | test expr-old-27.11 {cancelled evaluation} -body { |
---|
605 | expr {0 && foo} |
---|
606 | } -returnCodes error -match glob -result * |
---|
607 | test expr-old-27.12 {cancelled evaluation} -body { |
---|
608 | expr {0 ? 1 : foo} |
---|
609 | } -returnCodes error -match glob -result * |
---|
610 | |
---|
611 | # Tcl_ExprBool as used in "if" statements |
---|
612 | |
---|
613 | test expr-old-28.1 {Tcl_ExprBoolean usage} { |
---|
614 | set a 1 |
---|
615 | if {2} {set a 2} |
---|
616 | set a |
---|
617 | } 2 |
---|
618 | test expr-old-28.2 {Tcl_ExprBoolean usage} { |
---|
619 | set a 1 |
---|
620 | if {0} {set a 2} |
---|
621 | set a |
---|
622 | } 1 |
---|
623 | test expr-old-28.3 {Tcl_ExprBoolean usage} { |
---|
624 | set a 1 |
---|
625 | if {1.2} {set a 2} |
---|
626 | set a |
---|
627 | } 2 |
---|
628 | test expr-old-28.4 {Tcl_ExprBoolean usage} { |
---|
629 | set a 1 |
---|
630 | if {-1.1} {set a 2} |
---|
631 | set a |
---|
632 | } 2 |
---|
633 | test expr-old-28.5 {Tcl_ExprBoolean usage} { |
---|
634 | set a 1 |
---|
635 | if {0.0} {set a 2} |
---|
636 | set a |
---|
637 | } 1 |
---|
638 | test expr-old-28.6 {Tcl_ExprBoolean usage} { |
---|
639 | set a 1 |
---|
640 | if {"YES"} {set a 2} |
---|
641 | set a |
---|
642 | } 2 |
---|
643 | test expr-old-28.7 {Tcl_ExprBoolean usage} { |
---|
644 | set a 1 |
---|
645 | if {"no"} {set a 2} |
---|
646 | set a |
---|
647 | } 1 |
---|
648 | test expr-old-28.8 {Tcl_ExprBoolean usage} { |
---|
649 | set a 1 |
---|
650 | if {"true"} {set a 2} |
---|
651 | set a |
---|
652 | } 2 |
---|
653 | test expr-old-28.9 {Tcl_ExprBoolean usage} { |
---|
654 | set a 1 |
---|
655 | if {"fAlse"} {set a 2} |
---|
656 | set a |
---|
657 | } 1 |
---|
658 | test expr-old-28.10 {Tcl_ExprBoolean usage} { |
---|
659 | set a 1 |
---|
660 | if {"on"} {set a 2} |
---|
661 | set a |
---|
662 | } 2 |
---|
663 | test expr-old-28.11 {Tcl_ExprBoolean usage} { |
---|
664 | set a 1 |
---|
665 | if {"Off"} {set a 2} |
---|
666 | set a |
---|
667 | } 1 |
---|
668 | test expr-old-28.12 {Tcl_ExprBool usage} { |
---|
669 | list [catch {if {"abc"} {}} msg] $msg |
---|
670 | } {1 {expected boolean value but got "abc"}} |
---|
671 | test expr-old-28.13 {Tcl_ExprBool usage} { |
---|
672 | list [catch {if {"ogle"} {}} msg] $msg |
---|
673 | } {1 {expected boolean value but got "ogle"}} |
---|
674 | test expr-old-28.14 {Tcl_ExprBool usage} { |
---|
675 | list [catch {if {"o"} {}} msg] $msg |
---|
676 | } {1 {expected boolean value but got "o"}} |
---|
677 | |
---|
678 | # Operands enclosed in braces |
---|
679 | |
---|
680 | test expr-old-29.1 {braces} {expr {{abc}}} abc |
---|
681 | test expr-old-29.2 {braces} {expr {{0o0010}}} 8 |
---|
682 | test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12 |
---|
683 | test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c" |
---|
684 | test expr-old-29.5 {braces} -body { |
---|
685 | expr "\{abc" |
---|
686 | } -returnCodes error -match glob -result * |
---|
687 | |
---|
688 | # Very long values |
---|
689 | |
---|
690 | test expr-old-30.1 {long values} { |
---|
691 | set a "0000 1111 2222 3333 4444" |
---|
692 | set a "$a | $a | $a | $a | $a" |
---|
693 | set a "$a || $a || $a || $a || $a" |
---|
694 | expr {$a} |
---|
695 | } {0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444} |
---|
696 | test expr-old-30.2 {long values} { |
---|
697 | set a "000000000000000000000000000000" |
---|
698 | set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5" |
---|
699 | expr $a |
---|
700 | } 5 |
---|
701 | |
---|
702 | # Expressions spanning multiple arguments |
---|
703 | |
---|
704 | test expr-old-31.1 {multiple arguments to expr command} { |
---|
705 | expr 4 + ( 6 *12) -3 |
---|
706 | } 73 |
---|
707 | test expr-old-31.2 {multiple arguments to expr command} -body { |
---|
708 | expr 2 + (3 + 4 |
---|
709 | } -returnCodes error -match glob -result * |
---|
710 | test expr-old-31.3 {multiple arguments to expr command} -body { |
---|
711 | expr 2 + 3 + |
---|
712 | } -returnCodes error -match glob -result * |
---|
713 | test expr-old-31.4 {multiple arguments to expr command} -body { |
---|
714 | expr 2 + 3 ) |
---|
715 | } -returnCodes error -match glob -result * |
---|
716 | |
---|
717 | # Math functions |
---|
718 | |
---|
719 | test expr-old-32.1 {math functions in expressions} { |
---|
720 | format %.6g [expr acos(0.5)] |
---|
721 | } {1.0472} |
---|
722 | test expr-old-32.2 {math functions in expressions} { |
---|
723 | format %.6g [expr asin(0.5)] |
---|
724 | } {0.523599} |
---|
725 | test expr-old-32.3 {math functions in expressions} { |
---|
726 | format %.6g [expr atan(1.0)] |
---|
727 | } {0.785398} |
---|
728 | test expr-old-32.4 {math functions in expressions} { |
---|
729 | format %.6g [expr atan2(2.0, 2.0)] |
---|
730 | } {0.785398} |
---|
731 | test expr-old-32.5 {math functions in expressions} { |
---|
732 | format %.6g [expr ceil(1.999)] |
---|
733 | } {2} |
---|
734 | test expr-old-32.6 {math functions in expressions} { |
---|
735 | format %.6g [expr cos(.1)] |
---|
736 | } {0.995004} |
---|
737 | test expr-old-32.7 {math functions in expressions} { |
---|
738 | format %.6g [expr cosh(.1)] |
---|
739 | } {1.005} |
---|
740 | test expr-old-32.8 {math functions in expressions} { |
---|
741 | format %.6g [expr exp(1.0)] |
---|
742 | } {2.71828} |
---|
743 | test expr-old-32.9 {math functions in expressions} { |
---|
744 | format %.6g [expr floor(2.000)] |
---|
745 | } {2} |
---|
746 | test expr-old-32.10 {math functions in expressions} { |
---|
747 | format %.6g [expr floor(2.001)] |
---|
748 | } {2} |
---|
749 | test expr-old-32.11 {math functions in expressions} { |
---|
750 | format %.6g [expr fmod(7.3, 3.2)] |
---|
751 | } {0.9} |
---|
752 | test expr-old-32.12 {math functions in expressions} { |
---|
753 | format %.6g [expr hypot(3.0, 4.0)] |
---|
754 | } {5} |
---|
755 | test expr-old-32.13 {math functions in expressions} { |
---|
756 | format %.6g [expr log(2.8)] |
---|
757 | } {1.02962} |
---|
758 | test expr-old-32.14 {math functions in expressions} { |
---|
759 | format %.6g [expr log10(2.8)] |
---|
760 | } {0.447158} |
---|
761 | test expr-old-32.15 {math functions in expressions} { |
---|
762 | format %.6g [expr pow(2.1, 3.1)] |
---|
763 | } {9.97424} |
---|
764 | test expr-old-32.16 {math functions in expressions} { |
---|
765 | format %.6g [expr sin(.1)] |
---|
766 | } {0.0998334} |
---|
767 | test expr-old-32.17 {math functions in expressions} { |
---|
768 | format %.6g [expr sinh(.1)] |
---|
769 | } {0.100167} |
---|
770 | test expr-old-32.18 {math functions in expressions} { |
---|
771 | format %.6g [expr sqrt(2.0)] |
---|
772 | } {1.41421} |
---|
773 | test expr-old-32.19 {math functions in expressions} { |
---|
774 | format %.6g [expr tan(0.8)] |
---|
775 | } {1.02964} |
---|
776 | test expr-old-32.20 {math functions in expressions} { |
---|
777 | format %.6g [expr tanh(0.8)] |
---|
778 | } {0.664037} |
---|
779 | test expr-old-32.21 {math functions in expressions} { |
---|
780 | format %.6g [expr abs(-1.8)] |
---|
781 | } {1.8} |
---|
782 | test expr-old-32.22 {math functions in expressions} { |
---|
783 | expr abs(10.0) |
---|
784 | } {10.0} |
---|
785 | test expr-old-32.23 {math functions in expressions} { |
---|
786 | format %.6g [expr abs(-4)] |
---|
787 | } {4} |
---|
788 | test expr-old-32.24 {math functions in expressions} { |
---|
789 | format %.6g [expr abs(66)] |
---|
790 | } {66} |
---|
791 | |
---|
792 | test expr-old-32.25a {math functions in expressions} { |
---|
793 | expr abs(0x8000000000000000) |
---|
794 | } [expr 1<<63] |
---|
795 | |
---|
796 | test expr-old-32.25b {math functions in expressions} { |
---|
797 | expr abs(0x80000000) |
---|
798 | } 2147483648 |
---|
799 | |
---|
800 | test expr-old-32.26 {math functions in expressions} { |
---|
801 | expr double(1) |
---|
802 | } {1.0} |
---|
803 | test expr-old-32.27 {math functions in expressions} { |
---|
804 | expr double(1.1) |
---|
805 | } {1.1} |
---|
806 | test expr-old-32.28 {math functions in expressions} { |
---|
807 | expr int(1) |
---|
808 | } {1} |
---|
809 | test expr-old-32.29 {math functions in expressions} { |
---|
810 | expr int(1.4) |
---|
811 | } {1} |
---|
812 | test expr-old-32.30 {math functions in expressions} { |
---|
813 | expr int(1.6) |
---|
814 | } {1} |
---|
815 | test expr-old-32.31 {math functions in expressions} { |
---|
816 | expr int(-1.4) |
---|
817 | } {-1} |
---|
818 | test expr-old-32.32 {math functions in expressions} { |
---|
819 | expr int(-1.6) |
---|
820 | } {-1} |
---|
821 | test expr-old-32.33 {math functions in expressions} { |
---|
822 | expr int(1e60) |
---|
823 | } 0 |
---|
824 | test expr-old-32.34 {math functions in expressions} { |
---|
825 | expr int(-1e60) |
---|
826 | } 0 |
---|
827 | test expr-old-32.35 {math functions in expressions} { |
---|
828 | expr round(1.49) |
---|
829 | } {1} |
---|
830 | test expr-old-32.36 {math functions in expressions} { |
---|
831 | expr round(1.51) |
---|
832 | } {2} |
---|
833 | test expr-old-32.37 {math functions in expressions} { |
---|
834 | expr round(-1.49) |
---|
835 | } {-1} |
---|
836 | test expr-old-32.38 {math functions in expressions} { |
---|
837 | expr round(-1.51) |
---|
838 | } {-2} |
---|
839 | test expr-old-32.39 {math functions in expressions} { |
---|
840 | expr round(1e60) |
---|
841 | } 999999999999999949387135297074018866963645011013410073083904 |
---|
842 | test expr-old-32.40 {math functions in expressions} { |
---|
843 | expr round(-1e60) |
---|
844 | } -999999999999999949387135297074018866963645011013410073083904 |
---|
845 | test expr-old-32.41 {math functions in expressions} { |
---|
846 | list [catch {expr pow(1.0 + 3.0 - 2, .8 * 5)} msg] $msg |
---|
847 | } {0 16.0} |
---|
848 | test expr-old-32.42 {math functions in expressions} { |
---|
849 | list [catch {expr hypot(5*.8,3)} msg] $msg |
---|
850 | } {0 5.0} |
---|
851 | test expr-old-32.43 {math functions in expressions} testmathfunctions { |
---|
852 | expr 2*T1() |
---|
853 | } 246 |
---|
854 | test expr-old-32.44 {math functions in expressions} testmathfunctions { |
---|
855 | expr T2()*3 |
---|
856 | } 1035 |
---|
857 | test expr-old-32.45 {math functions in expressions} { |
---|
858 | expr (0 <= rand()) && (rand() < 1) |
---|
859 | } {1} |
---|
860 | test expr-old-32.46 {math functions in expressions} -body { |
---|
861 | list [catch {expr rand(24)} msg] $msg |
---|
862 | } -match glob -result {1 {too many arguments for math function*}} |
---|
863 | test expr-old-32.47 {math functions in expressions} -body { |
---|
864 | list [catch {expr srand()} msg] $msg |
---|
865 | } -match glob -result {1 {too few arguments for math function*}} |
---|
866 | test expr-old-32.48 {math functions in expressions} -body { |
---|
867 | expr srand(3.79) |
---|
868 | } -returnCodes error -match glob -result * |
---|
869 | test expr-old-32.49 {math functions in expressions} -body { |
---|
870 | expr srand("") |
---|
871 | } -returnCodes error -match glob -result * |
---|
872 | test expr-old-32.50 {math functions in expressions} { |
---|
873 | set result [expr round(srand(12345) * 1000)] |
---|
874 | for {set i 0} {$i < 10} {incr i} { |
---|
875 | lappend result [expr round(rand() * 1000)] |
---|
876 | } |
---|
877 | set result |
---|
878 | } {97 834 948 36 12 51 766 585 914 784 333} |
---|
879 | test expr-old-32.51 {math functions in expressions} -body { |
---|
880 | expr {srand([lindex "6ty" 0])} |
---|
881 | } -returnCodes error -match glob -result * |
---|
882 | test expr-old-32.52 {math functions in expressions} { |
---|
883 | expr {srand(int(1<<37)) < 1} |
---|
884 | } {1} |
---|
885 | test expr-old-32.53 {math functions in expressions} { |
---|
886 | expr {srand((1<<31) - 1) > 0} |
---|
887 | } {1} |
---|
888 | |
---|
889 | test expr-old-33.1 {conversions and fancy args to math functions} { |
---|
890 | expr hypot ( 3 , 4 ) |
---|
891 | } 5.0 |
---|
892 | test expr-old-33.2 {conversions and fancy args to math functions} { |
---|
893 | expr hypot ( (2.0+1.0) , 4 ) |
---|
894 | } 5.0 |
---|
895 | test expr-old-33.3 {conversions and fancy args to math functions} { |
---|
896 | expr hypot ( 3 , (3.0 + 1.0) ) |
---|
897 | } 5.0 |
---|
898 | test expr-old-33.4 {conversions and fancy args to math functions} { |
---|
899 | format %.6g [expr cos(acos(0.1))] |
---|
900 | } 0.1 |
---|
901 | |
---|
902 | test expr-old-34.1 {errors in math functions} -body { |
---|
903 | list [catch {expr func_2(1.0)} msg] $msg |
---|
904 | } -match glob -result {1 {* "*func_2"}} |
---|
905 | test expr-old-34.2 {errors in math functions} -body { |
---|
906 | expr func|(1.0) |
---|
907 | } -returnCodes error -match glob -result * |
---|
908 | test expr-old-34.3 {errors in math functions} { |
---|
909 | list [catch {expr {hypot("a b", 2.0)}} msg] $msg |
---|
910 | } {1 {expected floating-point number but got "a b"}} |
---|
911 | test expr-old-34.4 {errors in math functions} -body { |
---|
912 | expr hypot(1.0 2.0) |
---|
913 | } -returnCodes error -match glob -result * |
---|
914 | test expr-old-34.5 {errors in math functions} -body { |
---|
915 | expr hypot(1.0, 2.0 |
---|
916 | } -returnCodes error -match glob -result * |
---|
917 | test expr-old-34.6 {errors in math functions} -body { |
---|
918 | expr hypot(1.0 , |
---|
919 | } -returnCodes error -match glob -result * |
---|
920 | test expr-old-34.7 {errors in math functions} -body { |
---|
921 | list [catch {expr hypot(1.0)} msg] $msg |
---|
922 | } -match glob -result {1 {too few arguments for math function*}} |
---|
923 | test expr-old-34.8 {errors in math functions} -body { |
---|
924 | list [catch {expr hypot(1.0, 2.0, 3.0)} msg] $msg |
---|
925 | } -match glob -result {1 {too many arguments for math function*}} |
---|
926 | test expr-old-34.9 {errors in math functions} { |
---|
927 | list [catch {expr acos(-2.0)} msg] $msg $errorCode |
---|
928 | } {1 {domain error: argument not in valid range} {ARITH DOMAIN {domain error: argument not in valid range}}} |
---|
929 | test expr-old-34.10 {errors in math functions} { |
---|
930 | list [catch {expr pow(-3, 1000001)} msg] $msg |
---|
931 | } {0 -Inf} |
---|
932 | test expr-old-34.11a {errors in math functions} !ieeeFloatingPoint { |
---|
933 | list [catch {expr pow(3, 1000001)} msg] $msg $errorCode |
---|
934 | } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}} |
---|
935 | test expr-old-34.11b {errors in math functions} ieeeFloatingPoint { |
---|
936 | list [catch {expr pow(3, 1000001)} msg] $msg |
---|
937 | } {0 Inf} |
---|
938 | test expr-old-34.12a {errors in math functions} !ieeeFloatingPoint { |
---|
939 | list [catch {expr -14.0*exp(100000)} msg] $msg $errorCode |
---|
940 | } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}} |
---|
941 | test expr-old-34.12b {errors in math functions} ieeeFloatingPoint { |
---|
942 | list [catch {expr -14.0*exp(100000)} msg] $msg |
---|
943 | } {0 -Inf} |
---|
944 | test expr-old-34.13 {errors in math functions} { |
---|
945 | expr wide(1.0e30) |
---|
946 | } 5076964154930102272 |
---|
947 | test expr-old-34.14 {errors in math functions} { |
---|
948 | expr wide(-1.0e30) |
---|
949 | } -5076964154930102272 |
---|
950 | test expr-old-34.15 {errors in math functions} { |
---|
951 | expr round(1.0e30) |
---|
952 | } 1000000000000000019884624838656 |
---|
953 | test expr-old-34.16 {errors in math functions} { |
---|
954 | expr round(-1.0e30) |
---|
955 | } -1000000000000000019884624838656 |
---|
956 | test expr-old-34.17 {errors in math functions} -constraints testmathfunctions \ |
---|
957 | -body { |
---|
958 | list [catch {expr T1(4)} msg] $msg |
---|
959 | } -match glob -result {1 {too many arguments for math function*}} |
---|
960 | |
---|
961 | test expr-old-36.1 {ExprLooksLikeInt procedure} -body { |
---|
962 | expr 0o289 |
---|
963 | } -returnCodes error -match glob -result {*invalid octal number*} |
---|
964 | test expr-old-36.2 {ExprLooksLikeInt procedure} { |
---|
965 | set x 0o289 |
---|
966 | list [catch {expr {$x+1}} msg] $msg |
---|
967 | } {1 {can't use invalid octal number as operand of "+"}} |
---|
968 | test expr-old-36.3 {ExprLooksLikeInt procedure} { |
---|
969 | list [catch {expr 0289.1} msg] $msg |
---|
970 | } {0 289.1} |
---|
971 | test expr-old-36.4 {ExprLooksLikeInt procedure} { |
---|
972 | set x 0289.1 |
---|
973 | list [catch {expr {$x+1}} msg] $msg |
---|
974 | } {0 290.1} |
---|
975 | test expr-old-36.5 {ExprLooksLikeInt procedure} { |
---|
976 | set x { +22} |
---|
977 | list [catch {expr {$x+1}} msg] $msg |
---|
978 | } {0 23} |
---|
979 | test expr-old-36.6 {ExprLooksLikeInt procedure} { |
---|
980 | set x { -22} |
---|
981 | list [catch {expr {$x+1}} msg] $msg |
---|
982 | } {0 -21} |
---|
983 | test expr-old-36.7 {ExprLooksLikeInt procedure} { |
---|
984 | list [catch {expr nan} msg] $msg |
---|
985 | } {1 {domain error: argument not in valid range}} |
---|
986 | test expr-old-36.8 {ExprLooksLikeInt procedure} { |
---|
987 | list [catch {expr 78e1} msg] $msg |
---|
988 | } {0 780.0} |
---|
989 | test expr-old-36.9 {ExprLooksLikeInt procedure} { |
---|
990 | list [catch {expr 24E1} msg] $msg |
---|
991 | } {0 240.0} |
---|
992 | test expr-old-36.10 {ExprLooksLikeInt procedure} -body { |
---|
993 | expr 78e |
---|
994 | } -returnCodes error -match glob -result * |
---|
995 | |
---|
996 | # test for [Bug #542588] |
---|
997 | test expr-old-36.11 {ExprLooksLikeInt procedure} { |
---|
998 | # define a "too large integer"; this one works also for 64bit arith |
---|
999 | set x 665802003400000000000000 |
---|
1000 | expr {$x+1} |
---|
1001 | } 665802003400000000000001 |
---|
1002 | |
---|
1003 | # tests for [Bug #587140] |
---|
1004 | test expr-old-36.12 {ExprLooksLikeInt procedure} { |
---|
1005 | set x "10;" |
---|
1006 | list [catch {expr {$x+1}} msg] $msg |
---|
1007 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
1008 | test expr-old-36.13 {ExprLooksLikeInt procedure} { |
---|
1009 | set x " +" |
---|
1010 | list [catch {expr {$x+1}} msg] $msg |
---|
1011 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
1012 | test expr-old-36.14 {ExprLooksLikeInt procedure} { |
---|
1013 | set x "123456789012345678901234567890 " |
---|
1014 | expr {$x+1} |
---|
1015 | } 123456789012345678901234567891 |
---|
1016 | test expr-old-36.15 {ExprLooksLikeInt procedure} { |
---|
1017 | set x "0o99 " |
---|
1018 | list [catch {expr {$x+1}} msg] $msg |
---|
1019 | } {1 {can't use invalid octal number as operand of "+"}} |
---|
1020 | test expr-old-36.16 {ExprLooksLikeInt procedure} { |
---|
1021 | set x " 0xffffffffffffffffffffffffffffffffffffff " |
---|
1022 | expr {$x+1} |
---|
1023 | } [expr 0x100000000000000000000000000000000000000] |
---|
1024 | |
---|
1025 | test expr-old-37.1 {Check that Tcl_ExprLong doesn't modify interpreter result if no error} testexprlong { |
---|
1026 | testexprlong 4+1 |
---|
1027 | } {This is a result: 5} |
---|
1028 | #Check for [Bug 1109484] |
---|
1029 | test expr-old-37.2 {Tcl_ExprLong handles wide ints gracefully} testexprlong { |
---|
1030 | testexprlong wide(1)+2 |
---|
1031 | } {This is a result: 3} |
---|
1032 | |
---|
1033 | test expr-old-37.3 {Tcl_ExprLong on the empty string} testexprlong { |
---|
1034 | testexprlong "" |
---|
1035 | } {This is a result: 0} |
---|
1036 | test expr-old-37.4 {Tcl_ExprLong coerces doubles} testexprlong { |
---|
1037 | testexprlong 3+.14159 |
---|
1038 | } {This is a result: 3} |
---|
1039 | test expr-old-37.5 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { |
---|
1040 | testexprlong 0x80000000 |
---|
1041 | } {This is a result: -2147483648} |
---|
1042 | test expr-old-37.6 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { |
---|
1043 | testexprlong 0xffffffff |
---|
1044 | } {This is a result: -1} |
---|
1045 | test expr-old-37.7 {Tcl_ExprLong handles overflows} \ |
---|
1046 | -constraints {testexprlong longIs32bit} \ |
---|
1047 | -match glob \ |
---|
1048 | -body { |
---|
1049 | list [catch {testexprlong 0x100000000} result] $result |
---|
1050 | } \ |
---|
1051 | -result {1 {integer value too large to represent*}} |
---|
1052 | test expr-old-37.8 {Tcl_ExprLong handles overflows} testexprlong { |
---|
1053 | testexprlong -0x80000000 |
---|
1054 | } {This is a result: -2147483648} |
---|
1055 | test expr-old-37.9 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { |
---|
1056 | testexprlong -0xffffffff |
---|
1057 | } {This is a result: 1} |
---|
1058 | test expr-old-37.10 {Tcl_ExprLong handles overflows} \ |
---|
1059 | -constraints {testexprlong longIs32bit} \ |
---|
1060 | -match glob \ |
---|
1061 | -body { |
---|
1062 | list [catch {testexprlong -0x100000000} result] $result |
---|
1063 | } \ |
---|
1064 | -result {1 {integer value too large to represent*}} |
---|
1065 | test expr-old-37.11 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { |
---|
1066 | testexprlong 2147483648. |
---|
1067 | } {This is a result: -2147483648} |
---|
1068 | test expr-old-37.12 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { |
---|
1069 | testexprlong 4294967295. |
---|
1070 | } {This is a result: -1} |
---|
1071 | test expr-old-37.13 {Tcl_ExprLong handles overflows} \ |
---|
1072 | -constraints {testexprlong longIs32bit} \ |
---|
1073 | -match glob \ |
---|
1074 | -body { |
---|
1075 | list [catch {testexprlong 4294967296.} result] $result |
---|
1076 | } \ |
---|
1077 | -result {1 {integer value too large to represent*}} |
---|
1078 | test expr-old-37.14 {Tcl_ExprLong handles overflows} testexprlong { |
---|
1079 | testexprlong -2147483648. |
---|
1080 | } {This is a result: -2147483648} |
---|
1081 | test expr-old-37.15 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { |
---|
1082 | testexprlong -4294967295. |
---|
1083 | } {This is a result: 1} |
---|
1084 | test expr-old-37.16 {Tcl_ExprLong handles overflows} \ |
---|
1085 | -constraints {testexprlong longIs32bit} \ |
---|
1086 | -match glob \ |
---|
1087 | -body { |
---|
1088 | list [catch {testexprlong 4294967296.} result] $result |
---|
1089 | } \ |
---|
1090 | -result {1 {integer value too large to represent*}} |
---|
1091 | |
---|
1092 | test expr-old-37.17 {Check that Tcl_ExprDouble doesn't modify interpreter result if no error} testexprdouble { |
---|
1093 | testexprdouble 4.+1. |
---|
1094 | } {This is a result: 5.0} |
---|
1095 | #Check for [Bug 1109484] |
---|
1096 | test expr-old-37.18 {Tcl_ExprDouble on the empty string} testexprdouble { |
---|
1097 | testexprdouble "" |
---|
1098 | } {This is a result: 0.0} |
---|
1099 | test expr-old-37.19 {Tcl_ExprDouble coerces wides} testexprdouble { |
---|
1100 | testexprdouble 1[string repeat 0 17] |
---|
1101 | } {This is a result: 1e+17} |
---|
1102 | test expr-old-37.20 {Tcl_ExprDouble coerces bignums} testexprdouble { |
---|
1103 | testexprdouble 1[string repeat 0 38] |
---|
1104 | } {This is a result: 1e+38} |
---|
1105 | test expr-old-37.21 {Tcl_ExprDouble handles overflows} testexprdouble { |
---|
1106 | testexprdouble 17976931348623157[string repeat 0 292]. |
---|
1107 | } {This is a result: 1.7976931348623157e+308} |
---|
1108 | test expr-old-37.22 {Tcl_ExprDouble handles overflows that look like int} \ |
---|
1109 | testexprdouble { |
---|
1110 | testexprdouble 17976931348623157[string repeat 0 292] |
---|
1111 | } {This is a result: 1.7976931348623157e+308} |
---|
1112 | test expr-old-37.23 {Tcl_ExprDouble handles overflows} \ |
---|
1113 | ieeeFloatingPoint&&testexprdouble { |
---|
1114 | testexprdouble 17976931348623165[string repeat 0 292]. |
---|
1115 | } {This is a result: Inf} |
---|
1116 | test expr-old-37.24 {Tcl_ExprDouble handles overflows that look like int} \ |
---|
1117 | ieeeFloatingPoint&&testexprdouble { |
---|
1118 | testexprdouble 17976931348623165[string repeat 0 292] |
---|
1119 | } {This is a result: Inf} |
---|
1120 | test expr-old-37.25 {Tcl_ExprDouble and NaN} \ |
---|
1121 | {ieeeFloatingPoint testexprdouble} { |
---|
1122 | list [catch {testexprdouble 0.0/0.0} result] $result |
---|
1123 | } {1 {domain error: argument not in valid range}} |
---|
1124 | |
---|
1125 | test expr-old-38.1 {Verify Tcl_ExprString's basic operation} -constraints {testexprstring} -body { |
---|
1126 | list [testexprstring "1+4"] [testexprstring "2*3+4.2"] \ |
---|
1127 | [catch {testexprstring "1+"} msg] $msg |
---|
1128 | } -match glob -result {5 10.2 1 *} |
---|
1129 | test expr-old-38.2 {Tcl_ExprString} testexprstring { |
---|
1130 | # This one is "magical" |
---|
1131 | testexprstring {} |
---|
1132 | } 0 |
---|
1133 | test expr-old-38.3 {Tcl_ExprString} -constraints testexprstring -body { |
---|
1134 | testexprstring { } |
---|
1135 | } -returnCodes error -match glob -result * |
---|
1136 | |
---|
1137 | # |
---|
1138 | # Test for bug #908375: rounding numbers that do not fit in a |
---|
1139 | # long but do fit in a wide |
---|
1140 | # |
---|
1141 | |
---|
1142 | test expr-old-39.1 {Rounding with wide result} { |
---|
1143 | set x 1.0e10 |
---|
1144 | set y [expr $x + 0.1] |
---|
1145 | catch { |
---|
1146 | set x [list [expr {$x == round($y)}] [expr $x == -round(-$y)]] |
---|
1147 | } |
---|
1148 | set x |
---|
1149 | } {1 1} |
---|
1150 | unset -nocomplain x y |
---|
1151 | |
---|
1152 | # |
---|
1153 | # TIP #255 min and max math functions |
---|
1154 | # |
---|
1155 | |
---|
1156 | test expr-old-40.1 {min math function} -body { |
---|
1157 | expr {min(0)} |
---|
1158 | } -result 0 |
---|
1159 | test expr-old-40.2 {min math function} -body { |
---|
1160 | expr {min(0.0)} |
---|
1161 | } -result 0.0 |
---|
1162 | test expr-old-40.3 {min math function} -body { |
---|
1163 | list [catch {expr {min()}} msg] $msg |
---|
1164 | } -result {1 {too few arguments to math function "min"}} |
---|
1165 | test expr-old-40.4 {min math function} -body { |
---|
1166 | expr {min(wide(-1) << 30, 4.5, -10)} |
---|
1167 | } -result [expr {wide(-1) << 30}] |
---|
1168 | test expr-old-40.5 {min math function} -body { |
---|
1169 | expr {min("a", 0)} |
---|
1170 | } -returnCodes error -match glob -result * |
---|
1171 | test expr-old-40.6 {min math function} -body { |
---|
1172 | expr {min(300, "0xFF")} |
---|
1173 | } -result 255 |
---|
1174 | |
---|
1175 | test expr-old-41.1 {max math function} -body { |
---|
1176 | expr {max(0)} |
---|
1177 | } -result 0 |
---|
1178 | test expr-old-41.2 {max math function} -body { |
---|
1179 | expr {max(0.0)} |
---|
1180 | } -result 0.0 |
---|
1181 | test expr-old-41.3 {max math function} -body { |
---|
1182 | list [catch {expr {max()}} msg] $msg |
---|
1183 | } -result {1 {too few arguments to math function "max"}} |
---|
1184 | test expr-old-41.4 {max math function} -body { |
---|
1185 | expr {max(wide(1) << 30, 4.5, -10)} |
---|
1186 | } -result [expr {wide(1) << 30}] |
---|
1187 | test expr-old-41.5 {max math function} -body { |
---|
1188 | expr {max("a", 0)} |
---|
1189 | } -returnCodes error -match glob -result * |
---|
1190 | test expr-old-41.6 {max math function} -body { |
---|
1191 | expr {max(200, "0xFF")} |
---|
1192 | } -result 255 |
---|
1193 | |
---|
1194 | # Special test for Pentium arithmetic bug of 1994: |
---|
1195 | |
---|
1196 | if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} { |
---|
1197 | puts "Warning: this machine contains a defective Pentium processor" |
---|
1198 | puts "that performs arithmetic incorrectly. I recommend that you" |
---|
1199 | puts "call Intel customer service immediately at 1-800-628-8686" |
---|
1200 | puts "to request a replacement processor." |
---|
1201 | } |
---|
1202 | |
---|
1203 | # cleanup |
---|
1204 | ::tcltest::cleanupTests |
---|
1205 | return |
---|
1206 | |
---|
1207 | # Local Variables: |
---|
1208 | # mode: tcl |
---|
1209 | # End: |
---|