1*4887Schin########################################################################
2*4887Schin#                                                                      #
3*4887Schin#               This software is part of the ast package               #
4*4887Schin#           Copyright (c) 1982-2007 AT&T Knowledge Ventures            #
5*4887Schin#                      and is licensed under the                       #
6*4887Schin#                  Common Public License, Version 1.0                  #
7*4887Schin#                      by AT&T Knowledge Ventures                      #
8*4887Schin#                                                                      #
9*4887Schin#                A copy of the License is available at                 #
10*4887Schin#            http://www.opensource.org/licenses/cpl1.0.txt             #
11*4887Schin#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
12*4887Schin#                                                                      #
13*4887Schin#              Information and Software Systems Research               #
14*4887Schin#                            AT&T Research                             #
15*4887Schin#                           Florham Park NJ                            #
16*4887Schin#                                                                      #
17*4887Schin#                  David Korn <dgk@research.att.com>                   #
18*4887Schin#                                                                      #
19*4887Schin########################################################################
20*4887Schinfunction err_exit
21*4887Schin{
22*4887Schin	print -u2 -n "\t"
23*4887Schin	print -u2 -r ${Command}[$1]: "${@:2}"
24*4887Schin	let Errors+=1
25*4887Schin}
26*4887Schinalias err_exit='err_exit $LINENO'
27*4887Schin
28*4887SchinCommand=${0##*/}
29*4887Schintrap '' FPE # NOTE: osf.alpha requires this (no ieee math)
30*4887Schininteger Errors=0
31*4887Schininteger x=1 y=2 z=3
32*4887Schinif	(( 2+2 != 4 ))
33*4887Schinthen	err_exit 2+2!=4
34*4887Schinfi
35*4887Schinif	((x+y!=z))
36*4887Schinthen	err_exit x+y!=z
37*4887Schinfi
38*4887Schinif	(($x+$y!=$z))
39*4887Schinthen	err_exit $x+$y!=$z
40*4887Schinfi
41*4887Schinif	(((x|y)!=z))
42*4887Schinthen	err_exit "(x|y)!=z"
43*4887Schinfi
44*4887Schinif	((y >= z))
45*4887Schinthen	err_exit "y>=z"
46*4887Schinfi
47*4887Schinif	((y+3 != z+2))
48*4887Schinthen	err_exit "y+3!=z+2"
49*4887Schinfi
50*4887Schinif	((y<<2 != 1<<3))
51*4887Schinthen	err_exit "y<<2!=1<<3"
52*4887Schinfi
53*4887Schinif	((133%10 != 3))
54*4887Schinthen	err_exit "133%10!=3"
55*4887Schin	if	(( 2.5 != 2.5 ))
56*4887Schin	then	err_exit 2.5!=2.5
57*4887Schin	fi
58*4887Schinfi
59*4887Schind=0
60*4887Schin((d || 1)) || err_exit 'd=0; ((d||1))'
61*4887Schinif	(( d++!=0))
62*4887Schinthen	err_exit "d++!=0"
63*4887Schinfi
64*4887Schinif	(( --d!=0))
65*4887Schinthen	err_exit "--d!=0"
66*4887Schinfi
67*4887Schinif	(( (d++,6)!=6 && d!=1))
68*4887Schinthen	err_exit '(d++,6)!=6 && d!=1'
69*4887Schinfi
70*4887Schind=0
71*4887Schinif	(( (1?2+1:3*4+d++)!=3 || d!=0))
72*4887Schinthen	err_exit '(1?2+1:3*4+d++) !=3'
73*4887Schinfi
74*4887Schinfor	((i=0; i < 20; i++))
75*4887Schindo	:
76*4887Schindone
77*4887Schinif	(( i != 20))
78*4887Schinthen	err_exit 'for (( expr)) failed'
79*4887Schinfi
80*4887Schinfor	((i=0; i < 20; i++)); do	: ; done
81*4887Schinif	(( i != 20))
82*4887Schinthen	err_exit 'for (( expr));... failed'
83*4887Schinfi
84*4887Schinfor	((i=0; i < 20; i++)) do	: ; done
85*4887Schinif	(( i != 20))
86*4887Schinthen	err_exit 'for (( expr))... failed'
87*4887Schinfi
88*4887Schinif	(( (i?0:1) ))
89*4887Schinthen	err_exit '(( (i?0:1) )) failed'
90*4887Schinfi
91*4887Schinif	(( (1 || 1 && 0) != 1 ))
92*4887Schinthen	err_exit '( (1 || 1 && 0) != 1) failed'
93*4887Schinfi
94*4887Schinif	(( (_=1)+(_x=0)-_ ))
95*4887Schinthen	err_exit '(_=1)+(_x=0)-_ failed'
96*4887Schinfi
97*4887Schinif	((  (3^6) != 5))
98*4887Schinthen	err_exit '((3^6) != 5) failed'
99*4887Schinfi
100*4887Schininteger x=1
101*4887Schinif	(( (x=-x) != -1 ))
102*4887Schinthen	err_exit '(x=-x) != -1 failed'
103*4887Schinfi
104*4887Schini=2
105*4887Schinif	(( 1$(($i))3 != 123 ))
106*4887Schinthen	err_exit ' 1$(($i))3 failed'
107*4887Schinfi
108*4887Schin((pi=4*atan(1.)))
109*4887Schinpoint=(
110*4887Schin	float x
111*4887Schin	float y
112*4887Schin)
113*4887Schin(( point.x = cos(pi/6), point.y = sin(pi/6) ))
114*4887Schinif	(( point.x*point.x + point.y*point.y > 1.01 ))
115*4887Schinthen	err_exit 'cos*cos +sin*sin > 1.01'
116*4887Schinfi
117*4887Schinif	(( point.x*point.x + point.y*point.y < .99 ))
118*4887Schinthen	err_exit 'cos*cos +sin*sin < .99'
119*4887Schinfi
120*4887Schinif [[ $((y=x=1.5)) != 1 ]]
121*4887Schinthen	err_exit 'typecast not working in arithmetic evaluation'
122*4887Schinfi
123*4887Schintypeset -E x=1.5
124*4887Schin( ((x++))  ) 2>/dev/null
125*4887Schinif [[ $? == 0 ]]
126*4887Schinthen	err_exit 'postincrement of floating point allowed'
127*4887Schinfi
128*4887Schin( ((++x))  ) 2>/dev/null
129*4887Schinif [[ $? == 0 ]]
130*4887Schinthen	err_exit 'preincrement of floating point allowed'
131*4887Schinfi
132*4887Schinx=1.5
133*4887Schin( ((x%1.1))  ) 2>/dev/null
134*4887Schinif [[ $? == 0 ]]
135*4887Schinthen	err_exit 'floating point allowed with % operator'
136*4887Schinfi
137*4887Schinx=.125
138*4887Schinif	[[ $(( 4 * x/2 )) != 0.25 ]]
139*4887Schinthen	err_exit '(( 4 * x/2 )) is not 0.25, with x=.125'
140*4887Schinfi
141*4887Schinif	[[ $(( pow(2,3) )) != 8 ]]
142*4887Schinthen	err_exit '$(( pow(2,3) )) != 8'
143*4887Schinfi
144*4887Schin( [[ $(( pow(2,(3)) )) == 8 ]] ) 2> /dev/null
145*4887Schinif	(( $? ))
146*4887Schinthen	err_exit '$(( pow(2,(3)) )) != 8'
147*4887Schinfi
148*4887Schinunset x
149*4887Schininteger x=1; integer x=1
150*4887Schinif	[[ $x != 1 ]]
151*4887Schinthen	err_exit 'two consecutive integer x=1 not working'
152*4887Schinfi
153*4887Schinunset z
154*4887Schin{ z=$(typeset -RZ2 z2; (( z2 = 8 )); print $z2) ;} 2>/dev/null
155*4887Schinif [[ $z != "08" ]]
156*4887Schinthen	err_exit "typeset -RZ2 leading 0 decimal not working [z=$z]"
157*4887Schinfi
158*4887Schin{ z=$(typeset -RZ3 z3; (( z3 = 8 )); print $z3) ;} 2>/dev/null
159*4887Schinif [[ $z != "008" ]]
160*4887Schinthen	err_exit "typeset -RZ3 leading 0 decimal not working [z=$z]"
161*4887Schinfi
162*4887Schinunset z
163*4887Schintypeset -Z3 z=010
164*4887Schin(( z=z+1))
165*4887Schinif	[[ $z != 011 ]]
166*4887Schinthen	err_exit "leading 0's in -Z not treated as decimal"
167*4887Schinfi
168*4887Schinunset x
169*4887Schininteger x=0
170*4887Schinif	[[ $((x+=1)) != 1  ]] || ((x!=1))
171*4887Schinthen	err_exit "+= not working"
172*4887Schin	x=1
173*4887Schinfi
174*4887Schinx=1
175*4887Schinif	[[ $((x*=5)) != 5  ]] || ((x!=5))
176*4887Schinthen	err_exit "*= not working"
177*4887Schin	x=5
178*4887Schinfi
179*4887Schinif	[[ $((x%=4)) != 1  ]] || ((x!=1))
180*4887Schinthen	err_exit "%= not working"
181*4887Schin	x=1
182*4887Schinfi
183*4887Schinif	[[ $((x|=6)) != 7  ]] || ((x!=7))
184*4887Schinthen	err_exit "|= not working"
185*4887Schin	x=7
186*4887Schinfi
187*4887Schinif	[[ $((x&=5)) != 5  ]] || ((x!=5))
188*4887Schinthen	err_exit "&= not working"
189*4887Schin	x=5
190*4887Schinfi
191*4887Schinfunction newscope
192*4887Schin{
193*4887Schin	float x=1.5
194*4887Schin	(( x += 1 ))
195*4887Schin	print -r -- $x
196*4887Schin}
197*4887Schinif	[[ $(newscope) != 2.5 ]]
198*4887Schinthen	err_exit "arithmetic using wrong scope"
199*4887Schinfi
200*4887Schinunset x
201*4887Schininteger y[3]=9 y[4]=2 i=3
202*4887Schin(( x = y[3] + y[4] ))
203*4887Schinif	[[ $x != 11 ]]
204*4887Schinthen	err_exit "constant index array arithmetic failure"
205*4887Schinfi
206*4887Schin(( x = $empty y[3] + y[4] ))
207*4887Schinif	[[ $x != 11 ]]
208*4887Schinthen	err_exit "empty constant index array arithmetic failure"
209*4887Schinfi
210*4887Schin(( x = y[i] + y[i+1] ))
211*4887Schinif	[[ $x != 11 ]]
212*4887Schinthen	err_exit "variable subscript index array arithmetic failure"
213*4887Schinfi
214*4887Schininteger a[5]=3 a[2]=4
215*4887Schin(( x = y[a[5]] + y[a[2]] ))
216*4887Schinif	[[ $x != 11 ]]
217*4887Schinthen	err_exit "nested subscript index array arithmetic failure"
218*4887Schinfi
219*4887Schinunset y
220*4887Schintypeset -Ai y
221*4887Schiny[three]=9 y[four]=2
222*4887Schinthree=four
223*4887Schinfour=three
224*4887Schin(( x = y[three] + y[four] ))
225*4887Schinif	[[ $x != 11 ]]
226*4887Schinthen	err_exit "constant associative array arithmetic failure"
227*4887Schinfi
228*4887Schin(( x = y[$three] + y[$four] ))
229*4887Schinif	[[ $x != 11 ]]
230*4887Schinthen	err_exit "variable subscript associative array arithmetic failure"
231*4887Schinfi
232*4887Schin$SHELL -nc '((a = 1))' 2> /dev/null || err_exit "sh -n fails with arithmetic"
233*4887Schin$SHELL -nc '((a.b++))' 2> /dev/null || err_exit "sh -n fails with arithmetic2"
234*4887Schinunset z
235*4887Schinfloat z=7.5
236*4887Schinif	{ (( z%2 != 1));} 2> /dev/null
237*4887Schinthen	err_exit '% not working on floating point'
238*4887Schinfi
239*4887Schinchr=(a ' ' '=' '\r' '\n' '\\' '\"' '$' "\\'" '[' ']' '(' ')' '<' '\xab' '\040' '`' '{' '}' '*' '\E')
240*4887Schinif	(('a' == 97))
241*4887Schinthen	val=(97 32  61 13 10 92 34 36 39 91 93 40 41 60 171 32 96 123 125 42 27)
242*4887Schinelse	val=(129 64 126 13 21 224 127 91 125 173 189 77 93 76 171 32 121 192 208 92 39 21)
243*4887Schinfi
244*4887Schinq=0
245*4887Schinfor ((i=0; i < ${#chr[@]}; i++))
246*4887Schindo	if	(( '${chr[i]}' != ${val[i]} ))
247*4887Schin	then	err_exit "(( '${chr[i]}'  !=  ${val[i]} ))"
248*4887Schin	fi
249*4887Schin	if	[[ $(( '${chr[i]}' )) != ${val[i]} ]]
250*4887Schin	then	err_exit "(( '${chr[i]}' )) !=  ${val[i]}"
251*4887Schin	fi
252*4887Schin	if	[[ $(( L'${chr[i]}' )) != ${val[i]} ]]
253*4887Schin	then	err_exit "(( '${chr[i]}' )) !=  ${val[i]}"
254*4887Schin	fi
255*4887Schin	if	eval '((' "'${chr[i]}'" != ${val[i]} '))'
256*4887Schin	then	err_exit "eval (( '${chr[i]}'  !=  ${val[i]} ))"
257*4887Schin	fi
258*4887Schin	if	eval '((' "'${chr[i]}'" != ${val[i]} ' + $q ))'
259*4887Schin	then	err_exit "eval (( '${chr[i]}'  !=  ${val[i]} ))"
260*4887Schin	fi
261*4887Schindone
262*4887Schinunset x
263*4887Schintypeset -ui x=4294967293
264*4887Schin[[ $x != 4294967293 ]]  && err_exit "unsigned integers not working"
265*4887Schinx=32767
266*4887Schinx=x+1
267*4887Schin[[ $x != 32768 ]]  && err_exit "unsigned integer addition not working"
268*4887Schinunset x
269*4887Schinfloat x=99999999999999999999999999
270*4887Schinif	(( x < 1e20 ))
271*4887Schinthen	err_exit 'large integer constants not working'
272*4887Schinfi
273*4887Schinunset x  y
274*4887Schinfunction foobar
275*4887Schin{
276*4887Schin	nameref x=$1
277*4887Schin	(( x +=1 ))
278*4887Schin	print $x
279*4887Schin}
280*4887Schinx=0 y=4
281*4887Schinif	[[ $(foobar y) != 5 ]]
282*4887Schinthen	err_exit 'name references in arithmetic statements in functions broken'
283*4887Schinfi
284*4887Schinif	(( 2**3 != pow(2,3) ))
285*4887Schinthen	err_exit '2**3 not working'
286*4887Schinfi
287*4887Schinif	(( 2**3*2 != pow(2,3)*2 ))
288*4887Schinthen	err_exit '2**3*2 not working'
289*4887Schinfi
290*4887Schinif	(( 4**3**2 != pow(4,pow(3,2)) ))
291*4887Schinthen	err_exit '4**3**2 not working'
292*4887Schinfi
293*4887Schinif	(( (4**3)**2 != pow(pow(4,3),2) ))
294*4887Schinthen	err_exit '(4**3)**2 not working'
295*4887Schinfi
296*4887Schintypeset -Z3 x=11
297*4887Schintypeset -i x
298*4887Schinif	(( x != 11 ))
299*4887Schinthen	err_exit '-Z3 not treated as decimal'
300*4887Schinfi
301*4887Schinunset x
302*4887Schintypeset -ui x=-1
303*4887Schin(( x >= 0 )) || err_exit 'unsigned integer not working'
304*4887Schin(( $x >= 0 )) || err_exit 'unsigned integer not working as $x'
305*4887Schinunset x
306*4887Schintypeset -ui42 x=50
307*4887Schinif	[[ $x != 42#18 ]]
308*4887Schinthen	err_exit 'display of unsigned integers in non-decimal bases wrong'
309*4887Schinfi
310*4887Schin$SHELL -c 'i=0;(( ofiles[i] != -1 && (ofiles[i] < mins || mins == -1) ));exit 0' 2> /dev/null || err_exit 'lexical error with arithemtic expression'
311*4887Schinrm -f core
312*4887Schin$SHELL -c '(( +1 == 1))' 2> /dev/null || err_exit 'unary + not working'
313*4887Schintypeset -E20 val=123.01234567890
314*4887Schin[[ $val == 123.0123456789 ]] || err_exit "rounding error val=$val"
315*4887Schinif	[[ $(print x$((10))=foo) != x10=foo ]]
316*4887Schinthen	err_exit 'parsing error with x$((10))=foo'
317*4887Schinfi
318*4887Schin$SHELL -c 'typeset x$((10))=foo' 2> /dev/null || err_exit 'typeset x$((10)) parse error'
319*4887Schinunset x
320*4887Schinx=$(( exp(log(2.0)) ))
321*4887Schin(( x > 1.999 && x < 2.001 )) || err_exit 'composite functions not working'
322*4887Schinunset x y n
323*4887Schintypeset -Z8 x=0 y=0
324*4887Schininteger n
325*4887Schinfor	(( n=0; n < 20; n++ ))
326*4887Schindo	let "x = $x+1"
327*4887Schin	(( y = $y+1 ))
328*4887Schindone
329*4887Schin(( x == n ))  || err_exit 'let with zero filled fields not working'
330*4887Schin(( y == n ))  || err_exit '((...)) with zero filled fields not working'
331*4887Schintypeset -LZ3 x=10
332*4887Schin[[ $(($x)) == 10 && $((1$x)) == 1010 ]] || err_exit 'zero filled fields not preserving leading zeros'
333*4887Schinunset y
334*4887Schin[[ $(let y=$x;print $y) == 10 && $(let y=1$x;print $y) == 1010 ]] || err_exit 'zero filled fields not preserving leading zeros with let'
335*4887Schinunset i ip ipx
336*4887Schintypeset -i hex=( 172 30 18 1)
337*4887Schintypeset -iu ip=0 ipx=0
338*4887Schininteger i
339*4887Schinfor	((i=0; i < 4; i++))
340*4887Schindo	(( ip =  (ip<<8) | hex[i]))
341*4887Schindone
342*4887Schinfor ((i=0; i < 4; i++))
343*4887Schindo	(( ipx = ip % 256 ))
344*4887Schin	(( ip /= 256 ))
345*4887Schin	(( ipx != hex[3-i] )) && err_exit "hex digit $((3-i)) not correct"
346*4887Schindone
347*4887Schinunset x
348*4887Schinx=010
349*4887Schin(( x == 8 )) || err_exit 'leading zeros not treated as octal arithmetic'
350*4887Schin(( $x == 8 )) || err_exit 'leading zeros not treated as octal arithmetic with $x'
351*4887Schinunset x
352*4887Schintypeset -Z x=010
353*4887Schin(( x == 10 )) || err_exit 'leading zeros not ignored for arithmetic'
354*4887Schin(( $x == 10 )) || err_exit 'leading zeros not ignored for arithmetic with $x'
355*4887Schintypeset -i i=x
356*4887Schin(( i == 10 )) || err_exit 'leading zeros not ignored for arithmetic assignment'
357*4887Schin(( ${x:0:1} == 0 )) || err_exit 'leading zero should not be stripped for x:a:b'
358*4887Schinc010=3
359*4887Schin(( c$x  == 3 )) || err_exit 'leading zero with variable should not be stripped'
360*4887Schin[[ $( ($SHELL -c '((++1))' 2>&1)2>/dev/null ) == *lvalue* ]] || err_exit "((--1)) not generating error message"
361*4887Schini=2
362*4887Schin(( "22" == 22 )) || err_exit "double quoted constants fail"
363*4887Schin(( "2$i" == 22 )) || err_exit "double quoted variables fail"
364*4887Schin(( "18+$i+2" == 22 )) || err_exit "double quoted expressions fail"
365*4887Schin# 04-04-28 bug fix
366*4887Schinunset i; typeset -i i=01-2
367*4887Schin(( i == -1 )) || err_exit "01-2 is not -1"
368*4887Schin
369*4887Schintrap 'rm -f /tmp/script$$ /tmp/data$$.[12]' EXIT
370*4887Schincat > /tmp/script$$ <<-\!
371*4887Schintests=$*
372*4887Schintypeset -A blop
373*4887Schinfunction blop.get
374*4887Schin{
375*4887Schin	.sh.value=777
376*4887Schin}
377*4887Schinfunction mkobj
378*4887Schin{
379*4887Schin	nameref obj=$1
380*4887Schin	obj=()
381*4887Schin	[[ $tests == *1* ]] && {
382*4887Schin		(( obj.foo = 1 ))
383*4887Schin		(( obj.bar = 2 ))
384*4887Schin		(( obj.baz = obj.foo + obj.bar ))	# ok
385*4887Schin		echo $obj
386*4887Schin	}
387*4887Schin	[[ $tests == *2* ]] && {
388*4887Schin		(( obj.faz = faz = obj.foo + obj.bar ))	# ok
389*4887Schin		echo $obj
390*4887Schin	}
391*4887Schin	[[ $tests == *3* ]] && {
392*4887Schin		# case 3, 'active' variable involved, w/ intermediate variable
393*4887Schin		(( obj.foz = foz = ${blop[1]} ))	# coredump
394*4887Schin		echo $obj
395*4887Schin	}
396*4887Schin	[[ $tests == *4* ]] && {
397*4887Schin		# case 4, 'active' variable, in two steps
398*4887Schin		(( foz = ${blop[1]} ))	# ok
399*4887Schin		(( obj.foz = foz ))		# ok
400*4887Schin		echo $obj
401*4887Schin	}
402*4887Schin	[[ $tests == *5* ]] && {
403*4887Schin		# case 5, 'active' variable involved, w/o intermediate variable
404*4887Schin		(( obj.fuz = ${blop[1]} ))	# coredump
405*4887Schin		echo $obj
406*4887Schin	}
407*4887Schin	[[ $tests == *6* ]] && {
408*4887Schin		echo $(( obj.baz = obj.foo + obj.bar ))	# coredump
409*4887Schin	}
410*4887Schin	[[ $tests == *7* ]] && {
411*4887Schin		echo $(( obj.foo + obj.bar ))	# coredump
412*4887Schin	}
413*4887Schin}
414*4887Schinmkobj bla
415*4887Schin!
416*4887Schinchmod +x /tmp/script$$
417*4887Schin[[ $(/tmp/script$$ 1) != '( bar=2 baz=3 foo=1 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
418*4887Schin[[ $(/tmp/script$$ 2) != '( faz=0 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
419*4887Schin[[ $(/tmp/script$$ 3) != '( foz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
420*4887Schin[[ $(/tmp/script$$ 4) != '( foz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
421*4887Schin[[ $(/tmp/script$$ 5) != '( fuz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
422*4887Schin[[ $(/tmp/script$$ 6) != '0' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
423*4887Schin[[ $(/tmp/script$$ 7) != '0' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
424*4887Schinunset foo
425*4887Schintypeset -F1 foo=123456789.19
426*4887Schin[[ $foo == 123456789.2 ]] || err_exit 'typeset -F1 not working correctly'
427*4887Schin
428*4887Schin# divide by zero
429*4887Schin
430*4887Schinfor expr in '1/(1/2)' '8%(1/2)' '8%(1.0/2)'
431*4887Schindo	[[ $( ( $SHELL -c "( (($expr)) )  || print ok" ) 2>/dev/null ) == ok ]] || err_exit "divide by zero not trapped: $expr"
432*4887Schindone
433*4887Schin
434*4887Schinfor expr in '1/(1.0/2)' '1/(1/2.0)'
435*4887Schindo	[[ $( ( $SHELL -c "( print -r -- \$(($expr)) )" ) 2>/dev/null ) == 2 ]] || err_exit "invalid value for: $expr"
436*4887Schindone
437*4887Schin[[ $((5||0)) == 1 ]] || err_exit '$((5||0))'" == $((5||0)) should be 1"
438*4887Schin$SHELL -c 'integer x=3 y=2; (( (y += x += 2) == 7  && x==5))' 2> /dev/null || err_exit '((y += x += 2)) not working'
439*4887Schin$SHELL -c 'b=0; [[ $((b?a=1:b=9)) == 9 ]]' 2> /dev/null || err_exit 'b?a=1:b=9 not working'
440*4887Schinunset x
441*4887Schin(( x = 4*atan(1.0) ))
442*4887Schin[[ $x == "$((x))" ]] || err_exit  '$x !- $((x)) when x is pi'
443*4887Schin$SHELL -c  "[[  ${x//./} == {14,100}(\d) ]]" 2> /dev/null || err_exit 'pi has less than 14 significant places'
444*4887Schinif	(( Inf+1 == Inf ))
445*4887Schinthen	[[ $(printf "%g\n" $((Inf))) == inf ]] || err_exit 'printf "%g\n" $((Inf)) fails'
446*4887Schin#	[[ $(printf "%g\n" $((Nan))) == inf ]] || err_exit 'printf "%g\n" $((Nan)) fails'
447*4887Schin	[[ $(printf "%g\n" Inf) == inf ]] || err_exit 'printf "%g\n" Inf fails'
448*4887Schin	[[ $(printf "%g\n" NaN) == nan ]] || err_exit 'printf "%g\n" NaN fails'
449*4887Schin	[[ $(print -- $((Inf))) == inf ]] || err_exit 'print -- $((Inf)) fails'
450*4887Schin	(( 1.0/0.0 == Inf )) || err_exit '1.0/0.0 != Inf'
451*4887Schin	[[ $(print -- $((0.0/0.0))) == nan ]] || err_exit '0.0/0.0 != NaN'
452*4887Schin	(( Inf*Inf == Inf )) || err_exit 'Inf*Inf != Inf'
453*4887Schin	(( NaN != NaN )) || err_exit 'NaN == NaN'
454*4887Schin	(( -5*Inf == -Inf )) || err_exit '-5*Inf != -Inf'
455*4887Schin	[[ $(print -- $((sqrt(-1.0)))) == nan ]]|| err_exit 'sqrt(-1.0) != NaN'
456*4887Schin	(( pow(1.0,Inf) == 1.0 )) || err_exit 'pow(1.0,Inf) != 1.0'
457*4887Schin	(( pow(Inf,0.0) == 1.0 )) || err_exit 'pow(Inf,0.0) != 1.0'
458*4887Schin	[[ $(print -- $((NaN/Inf))) == nan ]] || err_exit 'NaN/Inf != NaN'
459*4887Schin	(( 4.0/Inf == 0.0 )) || err_exit '4.0/Inf != 0.0'
460*4887Schinelse	err_exit 'Inf and NaN not working'
461*4887Schinfi
462*4887Schinunset x y
463*4887Schinfloat x=14.555 y
464*4887Schiny=$(printf "%a" x)
465*4887Schin(( x == y )) || err_exit "output of printf %a not self preserving -- expected $x, got $y"
466*4887Schinexit $((Errors))
467