14887Schin########################################################################
24887Schin#                                                                      #
34887Schin#               This software is part of the ast package               #
4*8462SApril.Chin@Sun.COM#          Copyright (c) 1982-2008 AT&T Intellectual Property          #
54887Schin#                      and is licensed under the                       #
64887Schin#                  Common Public License, Version 1.0                  #
7*8462SApril.Chin@Sun.COM#                    by AT&T Intellectual Property                     #
84887Schin#                                                                      #
94887Schin#                A copy of the License is available at                 #
104887Schin#            http://www.opensource.org/licenses/cpl1.0.txt             #
114887Schin#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
124887Schin#                                                                      #
134887Schin#              Information and Software Systems Research               #
144887Schin#                            AT&T Research                             #
154887Schin#                           Florham Park NJ                            #
164887Schin#                                                                      #
174887Schin#                  David Korn <dgk@research.att.com>                   #
184887Schin#                                                                      #
194887Schin########################################################################
204887Schinfunction err_exit
214887Schin{
224887Schin	print -u2 -n "\t"
234887Schin	print -u2 -r ${Command}[$1]: "${@:2}"
244887Schin	let Errors+=1
254887Schin}
264887Schinalias err_exit='err_exit $LINENO'
274887Schin
284887SchinCommand=${0##*/}
294887Schintrap '' FPE # NOTE: osf.alpha requires this (no ieee math)
304887Schininteger Errors=0
314887Schininteger x=1 y=2 z=3
324887Schinif	(( 2+2 != 4 ))
334887Schinthen	err_exit 2+2!=4
344887Schinfi
354887Schinif	((x+y!=z))
364887Schinthen	err_exit x+y!=z
374887Schinfi
384887Schinif	(($x+$y!=$z))
394887Schinthen	err_exit $x+$y!=$z
404887Schinfi
414887Schinif	(((x|y)!=z))
424887Schinthen	err_exit "(x|y)!=z"
434887Schinfi
444887Schinif	((y >= z))
454887Schinthen	err_exit "y>=z"
464887Schinfi
474887Schinif	((y+3 != z+2))
484887Schinthen	err_exit "y+3!=z+2"
494887Schinfi
504887Schinif	((y<<2 != 1<<3))
514887Schinthen	err_exit "y<<2!=1<<3"
524887Schinfi
534887Schinif	((133%10 != 3))
544887Schinthen	err_exit "133%10!=3"
554887Schin	if	(( 2.5 != 2.5 ))
564887Schin	then	err_exit 2.5!=2.5
574887Schin	fi
584887Schinfi
594887Schind=0
604887Schin((d || 1)) || err_exit 'd=0; ((d||1))'
614887Schinif	(( d++!=0))
624887Schinthen	err_exit "d++!=0"
634887Schinfi
644887Schinif	(( --d!=0))
654887Schinthen	err_exit "--d!=0"
664887Schinfi
674887Schinif	(( (d++,6)!=6 && d!=1))
684887Schinthen	err_exit '(d++,6)!=6 && d!=1'
694887Schinfi
704887Schind=0
714887Schinif	(( (1?2+1:3*4+d++)!=3 || d!=0))
724887Schinthen	err_exit '(1?2+1:3*4+d++) !=3'
734887Schinfi
744887Schinfor	((i=0; i < 20; i++))
754887Schindo	:
764887Schindone
774887Schinif	(( i != 20))
784887Schinthen	err_exit 'for (( expr)) failed'
794887Schinfi
804887Schinfor	((i=0; i < 20; i++)); do	: ; done
814887Schinif	(( i != 20))
824887Schinthen	err_exit 'for (( expr));... failed'
834887Schinfi
844887Schinfor	((i=0; i < 20; i++)) do	: ; done
854887Schinif	(( i != 20))
864887Schinthen	err_exit 'for (( expr))... failed'
874887Schinfi
884887Schinif	(( (i?0:1) ))
894887Schinthen	err_exit '(( (i?0:1) )) failed'
904887Schinfi
914887Schinif	(( (1 || 1 && 0) != 1 ))
924887Schinthen	err_exit '( (1 || 1 && 0) != 1) failed'
934887Schinfi
944887Schinif	(( (_=1)+(_x=0)-_ ))
954887Schinthen	err_exit '(_=1)+(_x=0)-_ failed'
964887Schinfi
974887Schinif	((  (3^6) != 5))
984887Schinthen	err_exit '((3^6) != 5) failed'
994887Schinfi
1004887Schininteger x=1
1014887Schinif	(( (x=-x) != -1 ))
1024887Schinthen	err_exit '(x=-x) != -1 failed'
1034887Schinfi
1044887Schini=2
1054887Schinif	(( 1$(($i))3 != 123 ))
1064887Schinthen	err_exit ' 1$(($i))3 failed'
1074887Schinfi
1084887Schin((pi=4*atan(1.)))
1094887Schinpoint=(
1104887Schin	float x
1114887Schin	float y
1124887Schin)
1134887Schin(( point.x = cos(pi/6), point.y = sin(pi/6) ))
1144887Schinif	(( point.x*point.x + point.y*point.y > 1.01 ))
1154887Schinthen	err_exit 'cos*cos +sin*sin > 1.01'
1164887Schinfi
1174887Schinif	(( point.x*point.x + point.y*point.y < .99 ))
1184887Schinthen	err_exit 'cos*cos +sin*sin < .99'
1194887Schinfi
1204887Schinif [[ $((y=x=1.5)) != 1 ]]
1214887Schinthen	err_exit 'typecast not working in arithmetic evaluation'
1224887Schinfi
1234887Schintypeset -E x=1.5
1244887Schin( ((x++))  ) 2>/dev/null
1254887Schinif [[ $? == 0 ]]
1264887Schinthen	err_exit 'postincrement of floating point allowed'
1274887Schinfi
1284887Schin( ((++x))  ) 2>/dev/null
1294887Schinif [[ $? == 0 ]]
1304887Schinthen	err_exit 'preincrement of floating point allowed'
1314887Schinfi
1324887Schinx=1.5
1334887Schin( ((x%1.1))  ) 2>/dev/null
1344887Schinif [[ $? == 0 ]]
1354887Schinthen	err_exit 'floating point allowed with % operator'
1364887Schinfi
1374887Schinx=.125
1384887Schinif	[[ $(( 4 * x/2 )) != 0.25 ]]
1394887Schinthen	err_exit '(( 4 * x/2 )) is not 0.25, with x=.125'
1404887Schinfi
1414887Schinif	[[ $(( pow(2,3) )) != 8 ]]
1424887Schinthen	err_exit '$(( pow(2,3) )) != 8'
1434887Schinfi
1444887Schin( [[ $(( pow(2,(3)) )) == 8 ]] ) 2> /dev/null
1454887Schinif	(( $? ))
1464887Schinthen	err_exit '$(( pow(2,(3)) )) != 8'
1474887Schinfi
1484887Schinunset x
1494887Schininteger x=1; integer x=1
1504887Schinif	[[ $x != 1 ]]
1514887Schinthen	err_exit 'two consecutive integer x=1 not working'
1524887Schinfi
1534887Schinunset z
1544887Schin{ z=$(typeset -RZ2 z2; (( z2 = 8 )); print $z2) ;} 2>/dev/null
1554887Schinif [[ $z != "08" ]]
1564887Schinthen	err_exit "typeset -RZ2 leading 0 decimal not working [z=$z]"
1574887Schinfi
1584887Schin{ z=$(typeset -RZ3 z3; (( z3 = 8 )); print $z3) ;} 2>/dev/null
1594887Schinif [[ $z != "008" ]]
1604887Schinthen	err_exit "typeset -RZ3 leading 0 decimal not working [z=$z]"
1614887Schinfi
1624887Schinunset z
1634887Schintypeset -Z3 z=010
1644887Schin(( z=z+1))
1654887Schinif	[[ $z != 011 ]]
1664887Schinthen	err_exit "leading 0's in -Z not treated as decimal"
1674887Schinfi
1684887Schinunset x
1694887Schininteger x=0
1704887Schinif	[[ $((x+=1)) != 1  ]] || ((x!=1))
1714887Schinthen	err_exit "+= not working"
1724887Schin	x=1
1734887Schinfi
1744887Schinx=1
1754887Schinif	[[ $((x*=5)) != 5  ]] || ((x!=5))
1764887Schinthen	err_exit "*= not working"
1774887Schin	x=5
1784887Schinfi
1794887Schinif	[[ $((x%=4)) != 1  ]] || ((x!=1))
1804887Schinthen	err_exit "%= not working"
1814887Schin	x=1
1824887Schinfi
1834887Schinif	[[ $((x|=6)) != 7  ]] || ((x!=7))
1844887Schinthen	err_exit "|= not working"
1854887Schin	x=7
1864887Schinfi
1874887Schinif	[[ $((x&=5)) != 5  ]] || ((x!=5))
1884887Schinthen	err_exit "&= not working"
1894887Schin	x=5
1904887Schinfi
1914887Schinfunction newscope
1924887Schin{
1934887Schin	float x=1.5
1944887Schin	(( x += 1 ))
1954887Schin	print -r -- $x
1964887Schin}
1974887Schinif	[[ $(newscope) != 2.5 ]]
1984887Schinthen	err_exit "arithmetic using wrong scope"
1994887Schinfi
2004887Schinunset x
2014887Schininteger y[3]=9 y[4]=2 i=3
2024887Schin(( x = y[3] + y[4] ))
2034887Schinif	[[ $x != 11 ]]
2044887Schinthen	err_exit "constant index array arithmetic failure"
2054887Schinfi
2064887Schin(( x = $empty y[3] + y[4] ))
2074887Schinif	[[ $x != 11 ]]
2084887Schinthen	err_exit "empty constant index array arithmetic failure"
2094887Schinfi
2104887Schin(( x = y[i] + y[i+1] ))
2114887Schinif	[[ $x != 11 ]]
2124887Schinthen	err_exit "variable subscript index array arithmetic failure"
2134887Schinfi
2144887Schininteger a[5]=3 a[2]=4
2154887Schin(( x = y[a[5]] + y[a[2]] ))
2164887Schinif	[[ $x != 11 ]]
2174887Schinthen	err_exit "nested subscript index array arithmetic failure"
2184887Schinfi
2194887Schinunset y
2204887Schintypeset -Ai y
2214887Schiny[three]=9 y[four]=2
2224887Schinthree=four
2234887Schinfour=three
2244887Schin(( x = y[three] + y[four] ))
2254887Schinif	[[ $x != 11 ]]
2264887Schinthen	err_exit "constant associative array arithmetic failure"
2274887Schinfi
2284887Schin(( x = y[$three] + y[$four] ))
2294887Schinif	[[ $x != 11 ]]
2304887Schinthen	err_exit "variable subscript associative array arithmetic failure"
2314887Schinfi
2324887Schin$SHELL -nc '((a = 1))' 2> /dev/null || err_exit "sh -n fails with arithmetic"
2334887Schin$SHELL -nc '((a.b++))' 2> /dev/null || err_exit "sh -n fails with arithmetic2"
2344887Schinunset z
2354887Schinfloat z=7.5
2364887Schinif	{ (( z%2 != 1));} 2> /dev/null
2374887Schinthen	err_exit '% not working on floating point'
2384887Schinfi
2394887Schinchr=(a ' ' '=' '\r' '\n' '\\' '\"' '$' "\\'" '[' ']' '(' ')' '<' '\xab' '\040' '`' '{' '}' '*' '\E')
2404887Schinif	(('a' == 97))
2414887Schinthen	val=(97 32  61 13 10 92 34 36 39 91 93 40 41 60 171 32 96 123 125 42 27)
2424887Schinelse	val=(129 64 126 13 21 224 127 91 125 173 189 77 93 76 171 32 121 192 208 92 39 21)
2434887Schinfi
2444887Schinq=0
2454887Schinfor ((i=0; i < ${#chr[@]}; i++))
2464887Schindo	if	(( '${chr[i]}' != ${val[i]} ))
2474887Schin	then	err_exit "(( '${chr[i]}'  !=  ${val[i]} ))"
2484887Schin	fi
2494887Schin	if	[[ $(( '${chr[i]}' )) != ${val[i]} ]]
2504887Schin	then	err_exit "(( '${chr[i]}' )) !=  ${val[i]}"
2514887Schin	fi
2524887Schin	if	[[ $(( L'${chr[i]}' )) != ${val[i]} ]]
2534887Schin	then	err_exit "(( '${chr[i]}' )) !=  ${val[i]}"
2544887Schin	fi
2554887Schin	if	eval '((' "'${chr[i]}'" != ${val[i]} '))'
2564887Schin	then	err_exit "eval (( '${chr[i]}'  !=  ${val[i]} ))"
2574887Schin	fi
2584887Schin	if	eval '((' "'${chr[i]}'" != ${val[i]} ' + $q ))'
2594887Schin	then	err_exit "eval (( '${chr[i]}'  !=  ${val[i]} ))"
2604887Schin	fi
2614887Schindone
2624887Schinunset x
2634887Schintypeset -ui x=4294967293
2644887Schin[[ $x != 4294967293 ]]  && err_exit "unsigned integers not working"
2654887Schinx=32767
2664887Schinx=x+1
2674887Schin[[ $x != 32768 ]]  && err_exit "unsigned integer addition not working"
2684887Schinunset x
2694887Schinfloat x=99999999999999999999999999
2704887Schinif	(( x < 1e20 ))
2714887Schinthen	err_exit 'large integer constants not working'
2724887Schinfi
2734887Schinunset x  y
2744887Schinfunction foobar
2754887Schin{
2764887Schin	nameref x=$1
2774887Schin	(( x +=1 ))
2784887Schin	print $x
2794887Schin}
2804887Schinx=0 y=4
2814887Schinif	[[ $(foobar y) != 5 ]]
2824887Schinthen	err_exit 'name references in arithmetic statements in functions broken'
2834887Schinfi
2844887Schinif	(( 2**3 != pow(2,3) ))
2854887Schinthen	err_exit '2**3 not working'
2864887Schinfi
2874887Schinif	(( 2**3*2 != pow(2,3)*2 ))
2884887Schinthen	err_exit '2**3*2 not working'
2894887Schinfi
2904887Schinif	(( 4**3**2 != pow(4,pow(3,2)) ))
2914887Schinthen	err_exit '4**3**2 not working'
2924887Schinfi
2934887Schinif	(( (4**3)**2 != pow(pow(4,3),2) ))
2944887Schinthen	err_exit '(4**3)**2 not working'
2954887Schinfi
2964887Schintypeset -Z3 x=11
2974887Schintypeset -i x
2984887Schinif	(( x != 11 ))
2994887Schinthen	err_exit '-Z3 not treated as decimal'
3004887Schinfi
3014887Schinunset x
3024887Schintypeset -ui x=-1
3034887Schin(( x >= 0 )) || err_exit 'unsigned integer not working'
3044887Schin(( $x >= 0 )) || err_exit 'unsigned integer not working as $x'
3054887Schinunset x
3064887Schintypeset -ui42 x=50
3074887Schinif	[[ $x != 42#18 ]]
3084887Schinthen	err_exit 'display of unsigned integers in non-decimal bases wrong'
3094887Schinfi
3104887Schin$SHELL -c 'i=0;(( ofiles[i] != -1 && (ofiles[i] < mins || mins == -1) ));exit 0' 2> /dev/null || err_exit 'lexical error with arithemtic expression'
3114887Schin$SHELL -c '(( +1 == 1))' 2> /dev/null || err_exit 'unary + not working'
3124887Schintypeset -E20 val=123.01234567890
3134887Schin[[ $val == 123.0123456789 ]] || err_exit "rounding error val=$val"
3144887Schinif	[[ $(print x$((10))=foo) != x10=foo ]]
3154887Schinthen	err_exit 'parsing error with x$((10))=foo'
3164887Schinfi
3174887Schin$SHELL -c 'typeset x$((10))=foo' 2> /dev/null || err_exit 'typeset x$((10)) parse error'
3184887Schinunset x
3194887Schinx=$(( exp(log(2.0)) ))
3204887Schin(( x > 1.999 && x < 2.001 )) || err_exit 'composite functions not working'
3214887Schinunset x y n
3224887Schintypeset -Z8 x=0 y=0
3234887Schininteger n
3244887Schinfor	(( n=0; n < 20; n++ ))
3254887Schindo	let "x = $x+1"
3264887Schin	(( y = $y+1 ))
3274887Schindone
3284887Schin(( x == n ))  || err_exit 'let with zero filled fields not working'
3294887Schin(( y == n ))  || err_exit '((...)) with zero filled fields not working'
330*8462SApril.Chin@Sun.COMtypeset -RZ3 x=10
3314887Schin[[ $(($x)) == 10 && $((1$x)) == 1010 ]] || err_exit 'zero filled fields not preserving leading zeros'
3324887Schinunset y
3334887Schin[[ $(let y=$x;print $y) == 10 && $(let y=1$x;print $y) == 1010 ]] || err_exit 'zero filled fields not preserving leading zeros with let'
3344887Schinunset i ip ipx
3354887Schintypeset -i hex=( 172 30 18 1)
3364887Schintypeset -iu ip=0 ipx=0
3374887Schininteger i
3384887Schinfor	((i=0; i < 4; i++))
3394887Schindo	(( ip =  (ip<<8) | hex[i]))
3404887Schindone
3414887Schinfor ((i=0; i < 4; i++))
3424887Schindo	(( ipx = ip % 256 ))
3434887Schin	(( ip /= 256 ))
3444887Schin	(( ipx != hex[3-i] )) && err_exit "hex digit $((3-i)) not correct"
3454887Schindone
3464887Schinunset x
3474887Schinx=010
3484887Schin(( x == 8 )) || err_exit 'leading zeros not treated as octal arithmetic'
3494887Schin(( $x == 8 )) || err_exit 'leading zeros not treated as octal arithmetic with $x'
3504887Schinunset x
3514887Schintypeset -Z x=010
3524887Schin(( x == 10 )) || err_exit 'leading zeros not ignored for arithmetic'
3534887Schin(( $x == 10 )) || err_exit 'leading zeros not ignored for arithmetic with $x'
3544887Schintypeset -i i=x
3554887Schin(( i == 10 )) || err_exit 'leading zeros not ignored for arithmetic assignment'
3564887Schin(( ${x:0:1} == 0 )) || err_exit 'leading zero should not be stripped for x:a:b'
3574887Schinc010=3
3584887Schin(( c$x  == 3 )) || err_exit 'leading zero with variable should not be stripped'
359*8462SApril.Chin@Sun.COM[[ $( ($SHELL -c '((++1))' 2>&1)2>/dev/null ) == *lvalue* ]] || err_exit "((++1)) not generating error message"
3604887Schini=2
3614887Schin(( "22" == 22 )) || err_exit "double quoted constants fail"
3624887Schin(( "2$i" == 22 )) || err_exit "double quoted variables fail"
3634887Schin(( "18+$i+2" == 22 )) || err_exit "double quoted expressions fail"
3644887Schin# 04-04-28 bug fix
3654887Schinunset i; typeset -i i=01-2
3664887Schin(( i == -1 )) || err_exit "01-2 is not -1"
3674887Schin
3684887Schintrap 'rm -f /tmp/script$$ /tmp/data$$.[12]' EXIT
3694887Schincat > /tmp/script$$ <<-\!
3704887Schintests=$*
3714887Schintypeset -A blop
3724887Schinfunction blop.get
3734887Schin{
3744887Schin	.sh.value=777
3754887Schin}
3764887Schinfunction mkobj
3774887Schin{
3784887Schin	nameref obj=$1
3794887Schin	obj=()
3804887Schin	[[ $tests == *1* ]] && {
3814887Schin		(( obj.foo = 1 ))
3824887Schin		(( obj.bar = 2 ))
3834887Schin		(( obj.baz = obj.foo + obj.bar ))	# ok
3844887Schin		echo $obj
3854887Schin	}
3864887Schin	[[ $tests == *2* ]] && {
3874887Schin		(( obj.faz = faz = obj.foo + obj.bar ))	# ok
3884887Schin		echo $obj
3894887Schin	}
3904887Schin	[[ $tests == *3* ]] && {
3914887Schin		# case 3, 'active' variable involved, w/ intermediate variable
3924887Schin		(( obj.foz = foz = ${blop[1]} ))	# coredump
3934887Schin		echo $obj
3944887Schin	}
3954887Schin	[[ $tests == *4* ]] && {
3964887Schin		# case 4, 'active' variable, in two steps
3974887Schin		(( foz = ${blop[1]} ))	# ok
3984887Schin		(( obj.foz = foz ))		# ok
3994887Schin		echo $obj
4004887Schin	}
4014887Schin	[[ $tests == *5* ]] && {
4024887Schin		# case 5, 'active' variable involved, w/o intermediate variable
4034887Schin		(( obj.fuz = ${blop[1]} ))	# coredump
4044887Schin		echo $obj
4054887Schin	}
4064887Schin	[[ $tests == *6* ]] && {
4074887Schin		echo $(( obj.baz = obj.foo + obj.bar ))	# coredump
4084887Schin	}
4094887Schin	[[ $tests == *7* ]] && {
4104887Schin		echo $(( obj.foo + obj.bar ))	# coredump
4114887Schin	}
4124887Schin}
4134887Schinmkobj bla
4144887Schin!
4154887Schinchmod +x /tmp/script$$
4164887Schin[[ $(/tmp/script$$ 1) != '( bar=2 baz=3 foo=1 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4174887Schin[[ $(/tmp/script$$ 2) != '( faz=0 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4184887Schin[[ $(/tmp/script$$ 3) != '( foz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4194887Schin[[ $(/tmp/script$$ 4) != '( foz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4204887Schin[[ $(/tmp/script$$ 5) != '( fuz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4214887Schin[[ $(/tmp/script$$ 6) != '0' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4224887Schin[[ $(/tmp/script$$ 7) != '0' ]] 2>/dev/null && err_exit 'compound var arithmetic failed'
4234887Schinunset foo
4244887Schintypeset -F1 foo=123456789.19
4254887Schin[[ $foo == 123456789.2 ]] || err_exit 'typeset -F1 not working correctly'
4264887Schin
4274887Schin# divide by zero
4284887Schin
4294887Schinfor expr in '1/(1/2)' '8%(1/2)' '8%(1.0/2)'
4304887Schindo	[[ $( ( $SHELL -c "( (($expr)) )  || print ok" ) 2>/dev/null ) == ok ]] || err_exit "divide by zero not trapped: $expr"
4314887Schindone
4324887Schin
4334887Schinfor expr in '1/(1.0/2)' '1/(1/2.0)'
4344887Schindo	[[ $( ( $SHELL -c "( print -r -- \$(($expr)) )" ) 2>/dev/null ) == 2 ]] || err_exit "invalid value for: $expr"
4354887Schindone
4364887Schin[[ $((5||0)) == 1 ]] || err_exit '$((5||0))'" == $((5||0)) should be 1"
4374887Schin$SHELL -c 'integer x=3 y=2; (( (y += x += 2) == 7  && x==5))' 2> /dev/null || err_exit '((y += x += 2)) not working'
4384887Schin$SHELL -c 'b=0; [[ $((b?a=1:b=9)) == 9 ]]' 2> /dev/null || err_exit 'b?a=1:b=9 not working'
4394887Schinunset x
4404887Schin(( x = 4*atan(1.0) ))
4414887Schin[[ $x == "$((x))" ]] || err_exit  '$x !- $((x)) when x is pi'
4424887Schin$SHELL -c  "[[  ${x//./} == {14,100}(\d) ]]" 2> /dev/null || err_exit 'pi has less than 14 significant places'
4434887Schinif	(( Inf+1 == Inf ))
444*8462SApril.Chin@Sun.COMthen	set \
445*8462SApril.Chin@Sun.COM		Inf		inf	\
446*8462SApril.Chin@Sun.COM		-Inf		-inf	\
447*8462SApril.Chin@Sun.COM		Nan		nan	\
448*8462SApril.Chin@Sun.COM		-Nan		-nan	\
449*8462SApril.Chin@Sun.COM		1.0/0.0		inf
450*8462SApril.Chin@Sun.COM	while	(( $# >= 2 ))
451*8462SApril.Chin@Sun.COM	do	x=$(printf "%g\n" $(($1)))
452*8462SApril.Chin@Sun.COM		[[ $x == $2 ]] || err_exit "printf '%g\\n' \$(($1)) failed -- expected $2, got $x"
453*8462SApril.Chin@Sun.COM		x=$(printf "%g\n" $1)
454*8462SApril.Chin@Sun.COM		[[ $x == $2 ]] || err_exit "printf '%g\\n' $1 failed -- expected $2, got $x"
455*8462SApril.Chin@Sun.COM		x=$(printf -- $(($1)))
456*8462SApril.Chin@Sun.COM		[[ $x == $2 ]] || err_exit "print -- \$(($1)) failed -- expected $2, got $x"
457*8462SApril.Chin@Sun.COM		shift 2
458*8462SApril.Chin@Sun.COM	done
4594887Schin	(( 1.0/0.0 == Inf )) || err_exit '1.0/0.0 != Inf'
460*8462SApril.Chin@Sun.COM	[[ $(print -- $((0.0/0.0))) == ?(-)nan ]] || err_exit '0.0/0.0 != NaN'
4614887Schin	(( Inf*Inf == Inf )) || err_exit 'Inf*Inf != Inf'
4624887Schin	(( NaN != NaN )) || err_exit 'NaN == NaN'
4634887Schin	(( -5*Inf == -Inf )) || err_exit '-5*Inf != -Inf'
464*8462SApril.Chin@Sun.COM	[[ $(print -- $((sqrt(-1.0)))) == ?(-)nan ]]|| err_exit 'sqrt(-1.0) != NaN'
4654887Schin	(( pow(1.0,Inf) == 1.0 )) || err_exit 'pow(1.0,Inf) != 1.0'
4664887Schin	(( pow(Inf,0.0) == 1.0 )) || err_exit 'pow(Inf,0.0) != 1.0'
467*8462SApril.Chin@Sun.COM	[[ $(print -- $((NaN/Inf))) == ?(-)nan ]] || err_exit 'NaN/Inf != NaN'
4684887Schin	(( 4.0/Inf == 0.0 )) || err_exit '4.0/Inf != 0.0'
4694887Schinelse	err_exit 'Inf and NaN not working'
4704887Schinfi
471*8462SApril.Chin@Sun.COMunset x y n r
472*8462SApril.Chin@Sun.COMn=14.555
473*8462SApril.Chin@Sun.COMfloat x=$n y
4744887Schiny=$(printf "%a" x)
475*8462SApril.Chin@Sun.COMr=$y
476*8462SApril.Chin@Sun.COM[[ $r == $n ]] || err_exit "output of printf %a not self preserving -- expected $x, got $y"
477*8462SApril.Chin@Sun.COMunset x y r
478*8462SApril.Chin@Sun.COMx=-0
479*8462SApril.Chin@Sun.COMy=$(printf "%g %g %g %g %g %g\n" -0. -0 $((-0)) x $x $((x)))
480*8462SApril.Chin@Sun.COMr="-0 -0 -0 -0 -0 -0"
481*8462SApril.Chin@Sun.COM[[ $y == "$r" ]] || err_exit "-0 vs -0.0 inconsistency -- expected '$r', got '$y'"
482*8462SApril.Chin@Sun.COM$SHELL -c '(( x=));:' 2> /dev/null && err_exit '((x=)) should be an error'
483*8462SApril.Chin@Sun.COM$SHELL -c '(( x+=));:' 2> /dev/null && err_exit '((x+=)) should be an error'
484*8462SApril.Chin@Sun.COM$SHELL -c '(( x=+));:' 2> /dev/null && err_exit '((x=+)) should be an error'
485*8462SApril.Chin@Sun.COM$SHELL -c 'x=();x.arr[0]=(z=3); ((x.arr[0].z=2))' 2> /dev/null || err_exit '(((x.arr[0].z=2)) should not be an error'
4864887Schinexit $((Errors))
487