14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 1982-2010 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 78462SApril.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##*/} 2910898Sroland.mainz@nrubsig.orginteger Errors=0 3010898Sroland.mainz@nrubsig.org 3110898Sroland.mainz@nrubsig.orgtmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 3210898Sroland.mainz@nrubsig.orgtrap "cd /; rm -rf $tmp" EXIT 3310898Sroland.mainz@nrubsig.org 344887Schintrap '' FPE # NOTE: osf.alpha requires this (no ieee math) 3510898Sroland.mainz@nrubsig.org 364887Schininteger x=1 y=2 z=3 374887Schinif (( 2+2 != 4 )) 384887Schinthen err_exit 2+2!=4 394887Schinfi 404887Schinif ((x+y!=z)) 414887Schinthen err_exit x+y!=z 424887Schinfi 434887Schinif (($x+$y!=$z)) 444887Schinthen err_exit $x+$y!=$z 454887Schinfi 464887Schinif (((x|y)!=z)) 474887Schinthen err_exit "(x|y)!=z" 484887Schinfi 494887Schinif ((y >= z)) 504887Schinthen err_exit "y>=z" 514887Schinfi 524887Schinif ((y+3 != z+2)) 534887Schinthen err_exit "y+3!=z+2" 544887Schinfi 554887Schinif ((y<<2 != 1<<3)) 564887Schinthen err_exit "y<<2!=1<<3" 574887Schinfi 584887Schinif ((133%10 != 3)) 594887Schinthen err_exit "133%10!=3" 604887Schin if (( 2.5 != 2.5 )) 614887Schin then err_exit 2.5!=2.5 624887Schin fi 634887Schinfi 644887Schind=0 654887Schin((d || 1)) || err_exit 'd=0; ((d||1))' 664887Schinif (( d++!=0)) 674887Schinthen err_exit "d++!=0" 684887Schinfi 694887Schinif (( --d!=0)) 704887Schinthen err_exit "--d!=0" 714887Schinfi 724887Schinif (( (d++,6)!=6 && d!=1)) 734887Schinthen err_exit '(d++,6)!=6 && d!=1' 744887Schinfi 754887Schind=0 764887Schinif (( (1?2+1:3*4+d++)!=3 || d!=0)) 774887Schinthen err_exit '(1?2+1:3*4+d++) !=3' 784887Schinfi 794887Schinfor ((i=0; i < 20; i++)) 804887Schindo : 814887Schindone 824887Schinif (( i != 20)) 834887Schinthen err_exit 'for (( expr)) failed' 844887Schinfi 854887Schinfor ((i=0; i < 20; i++)); do : ; done 864887Schinif (( i != 20)) 874887Schinthen err_exit 'for (( expr));... failed' 884887Schinfi 894887Schinfor ((i=0; i < 20; i++)) do : ; done 904887Schinif (( i != 20)) 914887Schinthen err_exit 'for (( expr))... failed' 924887Schinfi 934887Schinif (( (i?0:1) )) 944887Schinthen err_exit '(( (i?0:1) )) failed' 954887Schinfi 964887Schinif (( (1 || 1 && 0) != 1 )) 974887Schinthen err_exit '( (1 || 1 && 0) != 1) failed' 984887Schinfi 994887Schinif (( (_=1)+(_x=0)-_ )) 1004887Schinthen err_exit '(_=1)+(_x=0)-_ failed' 1014887Schinfi 1024887Schinif (( (3^6) != 5)) 1034887Schinthen err_exit '((3^6) != 5) failed' 1044887Schinfi 1054887Schininteger x=1 1064887Schinif (( (x=-x) != -1 )) 1074887Schinthen err_exit '(x=-x) != -1 failed' 1084887Schinfi 1094887Schini=2 1104887Schinif (( 1$(($i))3 != 123 )) 1114887Schinthen err_exit ' 1$(($i))3 failed' 1124887Schinfi 1134887Schin((pi=4*atan(1.))) 1144887Schinpoint=( 1154887Schin float x 1164887Schin float y 1174887Schin) 1184887Schin(( point.x = cos(pi/6), point.y = sin(pi/6) )) 1194887Schinif (( point.x*point.x + point.y*point.y > 1.01 )) 1204887Schinthen err_exit 'cos*cos +sin*sin > 1.01' 1214887Schinfi 1224887Schinif (( point.x*point.x + point.y*point.y < .99 )) 1234887Schinthen err_exit 'cos*cos +sin*sin < .99' 1244887Schinfi 1254887Schinif [[ $((y=x=1.5)) != 1 ]] 1264887Schinthen err_exit 'typecast not working in arithmetic evaluation' 1274887Schinfi 1284887Schintypeset -E x=1.5 1294887Schin( ((x++)) ) 2>/dev/null 1304887Schinif [[ $? == 0 ]] 1314887Schinthen err_exit 'postincrement of floating point allowed' 1324887Schinfi 1334887Schin( ((++x)) ) 2>/dev/null 1344887Schinif [[ $? == 0 ]] 1354887Schinthen err_exit 'preincrement of floating point allowed' 1364887Schinfi 1374887Schinx=1.5 1384887Schin( ((x%1.1)) ) 2>/dev/null 1394887Schinif [[ $? == 0 ]] 1404887Schinthen err_exit 'floating point allowed with % operator' 1414887Schinfi 1424887Schinx=.125 14310898Sroland.mainz@nrubsig.orgif [[ $(( 4 * x/2 )) != 0.25 ]] 1444887Schinthen err_exit '(( 4 * x/2 )) is not 0.25, with x=.125' 1454887Schinfi 1464887Schinif [[ $(( pow(2,3) )) != 8 ]] 1474887Schinthen err_exit '$(( pow(2,3) )) != 8' 1484887Schinfi 1494887Schin( [[ $(( pow(2,(3)) )) == 8 ]] ) 2> /dev/null 1504887Schinif (( $? )) 1514887Schinthen err_exit '$(( pow(2,(3)) )) != 8' 1524887Schinfi 1534887Schinunset x 1544887Schininteger x=1; integer x=1 1554887Schinif [[ $x != 1 ]] 1564887Schinthen err_exit 'two consecutive integer x=1 not working' 1574887Schinfi 1584887Schinunset z 1594887Schin{ z=$(typeset -RZ2 z2; (( z2 = 8 )); print $z2) ;} 2>/dev/null 1604887Schinif [[ $z != "08" ]] 1614887Schinthen err_exit "typeset -RZ2 leading 0 decimal not working [z=$z]" 1624887Schinfi 1634887Schin{ z=$(typeset -RZ3 z3; (( z3 = 8 )); print $z3) ;} 2>/dev/null 1644887Schinif [[ $z != "008" ]] 1654887Schinthen err_exit "typeset -RZ3 leading 0 decimal not working [z=$z]" 1664887Schinfi 1674887Schinunset z 1684887Schintypeset -Z3 z=010 1694887Schin(( z=z+1)) 1704887Schinif [[ $z != 011 ]] 1714887Schinthen err_exit "leading 0's in -Z not treated as decimal" 1724887Schinfi 1734887Schinunset x 1744887Schininteger x=0 1754887Schinif [[ $((x+=1)) != 1 ]] || ((x!=1)) 1764887Schinthen err_exit "+= not working" 1774887Schin x=1 1784887Schinfi 1794887Schinx=1 1804887Schinif [[ $((x*=5)) != 5 ]] || ((x!=5)) 1814887Schinthen err_exit "*= not working" 1824887Schin x=5 1834887Schinfi 1844887Schinif [[ $((x%=4)) != 1 ]] || ((x!=1)) 1854887Schinthen err_exit "%= not working" 1864887Schin x=1 1874887Schinfi 1884887Schinif [[ $((x|=6)) != 7 ]] || ((x!=7)) 1894887Schinthen err_exit "|= not working" 1904887Schin x=7 1914887Schinfi 1924887Schinif [[ $((x&=5)) != 5 ]] || ((x!=5)) 1934887Schinthen err_exit "&= not working" 1944887Schin x=5 1954887Schinfi 1964887Schinfunction newscope 1974887Schin{ 19810898Sroland.mainz@nrubsig.org float x=1.5 1994887Schin (( x += 1 )) 2004887Schin print -r -- $x 2014887Schin} 2024887Schinif [[ $(newscope) != 2.5 ]] 2034887Schinthen err_exit "arithmetic using wrong scope" 2044887Schinfi 2054887Schinunset x 2064887Schininteger y[3]=9 y[4]=2 i=3 2074887Schin(( x = y[3] + y[4] )) 2084887Schinif [[ $x != 11 ]] 2094887Schinthen err_exit "constant index array arithmetic failure" 2104887Schinfi 2114887Schin(( x = $empty y[3] + y[4] )) 2124887Schinif [[ $x != 11 ]] 2134887Schinthen err_exit "empty constant index array arithmetic failure" 2144887Schinfi 2154887Schin(( x = y[i] + y[i+1] )) 2164887Schinif [[ $x != 11 ]] 2174887Schinthen err_exit "variable subscript index array arithmetic failure" 2184887Schinfi 2194887Schininteger a[5]=3 a[2]=4 2204887Schin(( x = y[a[5]] + y[a[2]] )) 2214887Schinif [[ $x != 11 ]] 2224887Schinthen err_exit "nested subscript index array arithmetic failure" 2234887Schinfi 2244887Schinunset y 2254887Schintypeset -Ai y 2264887Schiny[three]=9 y[four]=2 2274887Schinthree=four 2284887Schinfour=three 2294887Schin(( x = y[three] + y[four] )) 2304887Schinif [[ $x != 11 ]] 2314887Schinthen err_exit "constant associative array arithmetic failure" 2324887Schinfi 2334887Schin(( x = y[$three] + y[$four] )) 2344887Schinif [[ $x != 11 ]] 2354887Schinthen err_exit "variable subscript associative array arithmetic failure" 2364887Schinfi 2374887Schin$SHELL -nc '((a = 1))' 2> /dev/null || err_exit "sh -n fails with arithmetic" 2384887Schin$SHELL -nc '((a.b++))' 2> /dev/null || err_exit "sh -n fails with arithmetic2" 2394887Schinunset z 2404887Schinfloat z=7.5 2414887Schinif { (( z%2 != 1));} 2> /dev/null 2424887Schinthen err_exit '% not working on floating point' 2434887Schinfi 2444887Schinchr=(a ' ' '=' '\r' '\n' '\\' '\"' '$' "\\'" '[' ']' '(' ')' '<' '\xab' '\040' '`' '{' '}' '*' '\E') 2454887Schinif (('a' == 97)) 2464887Schinthen val=(97 32 61 13 10 92 34 36 39 91 93 40 41 60 171 32 96 123 125 42 27) 2474887Schinelse val=(129 64 126 13 21 224 127 91 125 173 189 77 93 76 171 32 121 192 208 92 39 21) 2484887Schinfi 2494887Schinq=0 2504887Schinfor ((i=0; i < ${#chr[@]}; i++)) 2514887Schindo if (( '${chr[i]}' != ${val[i]} )) 2524887Schin then err_exit "(( '${chr[i]}' != ${val[i]} ))" 2534887Schin fi 2544887Schin if [[ $(( '${chr[i]}' )) != ${val[i]} ]] 2554887Schin then err_exit "(( '${chr[i]}' )) != ${val[i]}" 2564887Schin fi 2574887Schin if [[ $(( L'${chr[i]}' )) != ${val[i]} ]] 2584887Schin then err_exit "(( '${chr[i]}' )) != ${val[i]}" 2594887Schin fi 2604887Schin if eval '((' "'${chr[i]}'" != ${val[i]} '))' 2614887Schin then err_exit "eval (( '${chr[i]}' != ${val[i]} ))" 2624887Schin fi 2634887Schin if eval '((' "'${chr[i]}'" != ${val[i]} ' + $q ))' 2644887Schin then err_exit "eval (( '${chr[i]}' != ${val[i]} ))" 2654887Schin fi 2664887Schindone 2674887Schinunset x 2684887Schintypeset -ui x=4294967293 2694887Schin[[ $x != 4294967293 ]] && err_exit "unsigned integers not working" 2704887Schinx=32767 2714887Schinx=x+1 2724887Schin[[ $x != 32768 ]] && err_exit "unsigned integer addition not working" 2734887Schinunset x 2744887Schinfloat x=99999999999999999999999999 2754887Schinif (( x < 1e20 )) 2764887Schinthen err_exit 'large integer constants not working' 2774887Schinfi 2784887Schinunset x y 2794887Schinfunction foobar 2804887Schin{ 2814887Schin nameref x=$1 2824887Schin (( x +=1 )) 2834887Schin print $x 2844887Schin} 2854887Schinx=0 y=4 2864887Schinif [[ $(foobar y) != 5 ]] 2874887Schinthen err_exit 'name references in arithmetic statements in functions broken' 2884887Schinfi 2894887Schinif (( 2**3 != pow(2,3) )) 2904887Schinthen err_exit '2**3 not working' 2914887Schinfi 2924887Schinif (( 2**3*2 != pow(2,3)*2 )) 2934887Schinthen err_exit '2**3*2 not working' 2944887Schinfi 2954887Schinif (( 4**3**2 != pow(4,pow(3,2)) )) 2964887Schinthen err_exit '4**3**2 not working' 2974887Schinfi 2984887Schinif (( (4**3)**2 != pow(pow(4,3),2) )) 2994887Schinthen err_exit '(4**3)**2 not working' 3004887Schinfi 3014887Schintypeset -Z3 x=11 3024887Schintypeset -i x 3034887Schinif (( x != 11 )) 3044887Schinthen err_exit '-Z3 not treated as decimal' 3054887Schinfi 3064887Schinunset x 3074887Schintypeset -ui x=-1 3084887Schin(( x >= 0 )) || err_exit 'unsigned integer not working' 3094887Schin(( $x >= 0 )) || err_exit 'unsigned integer not working as $x' 3104887Schinunset x 3114887Schintypeset -ui42 x=50 3124887Schinif [[ $x != 42#18 ]] 3134887Schinthen err_exit 'display of unsigned integers in non-decimal bases wrong' 3144887Schinfi 3154887Schin$SHELL -c 'i=0;(( ofiles[i] != -1 && (ofiles[i] < mins || mins == -1) ));exit 0' 2> /dev/null || err_exit 'lexical error with arithemtic expression' 3164887Schin$SHELL -c '(( +1 == 1))' 2> /dev/null || err_exit 'unary + not working' 3174887Schintypeset -E20 val=123.01234567890 3184887Schin[[ $val == 123.0123456789 ]] || err_exit "rounding error val=$val" 3194887Schinif [[ $(print x$((10))=foo) != x10=foo ]] 3204887Schinthen err_exit 'parsing error with x$((10))=foo' 3214887Schinfi 3224887Schin$SHELL -c 'typeset x$((10))=foo' 2> /dev/null || err_exit 'typeset x$((10)) parse error' 3234887Schinunset x 3244887Schinx=$(( exp(log(2.0)) )) 3254887Schin(( x > 1.999 && x < 2.001 )) || err_exit 'composite functions not working' 3264887Schinunset x y n 3274887Schintypeset -Z8 x=0 y=0 3284887Schininteger n 3294887Schinfor (( n=0; n < 20; n++ )) 3304887Schindo let "x = $x+1" 3314887Schin (( y = $y+1 )) 3324887Schindone 3334887Schin(( x == n )) || err_exit 'let with zero filled fields not working' 3344887Schin(( y == n )) || err_exit '((...)) with zero filled fields not working' 3358462SApril.Chin@Sun.COMtypeset -RZ3 x=10 3364887Schin[[ $(($x)) == 10 && $((1$x)) == 1010 ]] || err_exit 'zero filled fields not preserving leading zeros' 3374887Schinunset y 3384887Schin[[ $(let y=$x;print $y) == 10 && $(let y=1$x;print $y) == 1010 ]] || err_exit 'zero filled fields not preserving leading zeros with let' 3394887Schinunset i ip ipx 3404887Schintypeset -i hex=( 172 30 18 1) 3414887Schintypeset -iu ip=0 ipx=0 3424887Schininteger i 3434887Schinfor ((i=0; i < 4; i++)) 3444887Schindo (( ip = (ip<<8) | hex[i])) 3454887Schindone 3464887Schinfor ((i=0; i < 4; i++)) 3474887Schindo (( ipx = ip % 256 )) 3484887Schin (( ip /= 256 )) 3494887Schin (( ipx != hex[3-i] )) && err_exit "hex digit $((3-i)) not correct" 35010898Sroland.mainz@nrubsig.orgdone 3514887Schinunset x 3524887Schinx=010 3534887Schin(( x == 8 )) || err_exit 'leading zeros not treated as octal arithmetic' 3544887Schin(( $x == 8 )) || err_exit 'leading zeros not treated as octal arithmetic with $x' 3554887Schinunset x 3564887Schintypeset -Z x=010 3574887Schin(( x == 10 )) || err_exit 'leading zeros not ignored for arithmetic' 3584887Schin(( $x == 10 )) || err_exit 'leading zeros not ignored for arithmetic with $x' 3594887Schintypeset -i i=x 3604887Schin(( i == 10 )) || err_exit 'leading zeros not ignored for arithmetic assignment' 3614887Schin(( ${x:0:1} == 0 )) || err_exit 'leading zero should not be stripped for x:a:b' 3624887Schinc010=3 3634887Schin(( c$x == 3 )) || err_exit 'leading zero with variable should not be stripped' 3648462SApril.Chin@Sun.COM[[ $( ($SHELL -c '((++1))' 2>&1)2>/dev/null ) == *lvalue* ]] || err_exit "((++1)) not generating error message" 3654887Schini=2 3664887Schin(( "22" == 22 )) || err_exit "double quoted constants fail" 3674887Schin(( "2$i" == 22 )) || err_exit "double quoted variables fail" 3684887Schin(( "18+$i+2" == 22 )) || err_exit "double quoted expressions fail" 3694887Schin# 04-04-28 bug fix 3704887Schinunset i; typeset -i i=01-2 3714887Schin(( i == -1 )) || err_exit "01-2 is not -1" 3724887Schin 37310898Sroland.mainz@nrubsig.orgcat > $tmp/script <<-\! 3744887Schintests=$* 3754887Schintypeset -A blop 3764887Schinfunction blop.get 3774887Schin{ 3784887Schin .sh.value=777 3794887Schin} 3804887Schinfunction mkobj 3814887Schin{ 3824887Schin nameref obj=$1 3834887Schin obj=() 3844887Schin [[ $tests == *1* ]] && { 3854887Schin (( obj.foo = 1 )) 3864887Schin (( obj.bar = 2 )) 3874887Schin (( obj.baz = obj.foo + obj.bar )) # ok 3884887Schin echo $obj 3894887Schin } 3904887Schin [[ $tests == *2* ]] && { 3914887Schin (( obj.faz = faz = obj.foo + obj.bar )) # ok 3924887Schin echo $obj 3934887Schin } 3944887Schin [[ $tests == *3* ]] && { 3954887Schin # case 3, 'active' variable involved, w/ intermediate variable 3964887Schin (( obj.foz = foz = ${blop[1]} )) # coredump 3974887Schin echo $obj 3984887Schin } 3994887Schin [[ $tests == *4* ]] && { 4004887Schin # case 4, 'active' variable, in two steps 4014887Schin (( foz = ${blop[1]} )) # ok 4024887Schin (( obj.foz = foz )) # ok 4034887Schin echo $obj 4044887Schin } 4054887Schin [[ $tests == *5* ]] && { 4064887Schin # case 5, 'active' variable involved, w/o intermediate variable 4074887Schin (( obj.fuz = ${blop[1]} )) # coredump 4084887Schin echo $obj 4094887Schin } 4104887Schin [[ $tests == *6* ]] && { 4114887Schin echo $(( obj.baz = obj.foo + obj.bar )) # coredump 4124887Schin } 4134887Schin [[ $tests == *7* ]] && { 4144887Schin echo $(( obj.foo + obj.bar )) # coredump 4154887Schin } 4164887Schin} 4174887Schinmkobj bla 4184887Schin! 41910898Sroland.mainz@nrubsig.orgchmod +x $tmp/script 42010898Sroland.mainz@nrubsig.org[[ $($tmp/script 1) != '( bar=2 baz=3 foo=1 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 42110898Sroland.mainz@nrubsig.org[[ $($tmp/script 2) != '( faz=0 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 42210898Sroland.mainz@nrubsig.org[[ $($tmp/script 3) != '( foz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 42310898Sroland.mainz@nrubsig.org[[ $($tmp/script 4) != '( foz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 42410898Sroland.mainz@nrubsig.org[[ $($tmp/script 5) != '( fuz=777 )' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 42510898Sroland.mainz@nrubsig.org[[ $($tmp/script 6) != '0' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 42610898Sroland.mainz@nrubsig.org[[ $($tmp/script 7) != '0' ]] 2>/dev/null && err_exit 'compound var arithmetic failed' 4274887Schinunset foo 4284887Schintypeset -F1 foo=123456789.19 4294887Schin[[ $foo == 123456789.2 ]] || err_exit 'typeset -F1 not working correctly' 4304887Schin 4314887Schin# divide by zero 4324887Schin 4334887Schinfor expr in '1/(1/2)' '8%(1/2)' '8%(1.0/2)' 4344887Schindo [[ $( ( $SHELL -c "( (($expr)) ) || print ok" ) 2>/dev/null ) == ok ]] || err_exit "divide by zero not trapped: $expr" 4354887Schindone 4364887Schin 4374887Schinfor expr in '1/(1.0/2)' '1/(1/2.0)' 4384887Schindo [[ $( ( $SHELL -c "( print -r -- \$(($expr)) )" ) 2>/dev/null ) == 2 ]] || err_exit "invalid value for: $expr" 4394887Schindone 4404887Schin[[ $((5||0)) == 1 ]] || err_exit '$((5||0))'" == $((5||0)) should be 1" 44110898Sroland.mainz@nrubsig.org$SHELL -c 'integer x=3 y=2; (( (y += x += 2) == 7 && x==5))' 2> /dev/null || err_exit '((y += x += 2)) not working' 4424887Schin$SHELL -c 'b=0; [[ $((b?a=1:b=9)) == 9 ]]' 2> /dev/null || err_exit 'b?a=1:b=9 not working' 4434887Schinunset x 4444887Schin(( x = 4*atan(1.0) )) 4454887Schin[[ $x == "$((x))" ]] || err_exit '$x !- $((x)) when x is pi' 4464887Schin$SHELL -c "[[ ${x//./} == {14,100}(\d) ]]" 2> /dev/null || err_exit 'pi has less than 14 significant places' 4474887Schinif (( Inf+1 == Inf )) 4488462SApril.Chin@Sun.COMthen set \ 4498462SApril.Chin@Sun.COM Inf inf \ 4508462SApril.Chin@Sun.COM -Inf -inf \ 4518462SApril.Chin@Sun.COM Nan nan \ 4528462SApril.Chin@Sun.COM -Nan -nan \ 4538462SApril.Chin@Sun.COM 1.0/0.0 inf 4548462SApril.Chin@Sun.COM while (( $# >= 2 )) 4558462SApril.Chin@Sun.COM do x=$(printf "%g\n" $(($1))) 4568462SApril.Chin@Sun.COM [[ $x == $2 ]] || err_exit "printf '%g\\n' \$(($1)) failed -- expected $2, got $x" 4578462SApril.Chin@Sun.COM x=$(printf "%g\n" $1) 4588462SApril.Chin@Sun.COM [[ $x == $2 ]] || err_exit "printf '%g\\n' $1 failed -- expected $2, got $x" 4598462SApril.Chin@Sun.COM x=$(printf -- $(($1))) 4608462SApril.Chin@Sun.COM [[ $x == $2 ]] || err_exit "print -- \$(($1)) failed -- expected $2, got $x" 4618462SApril.Chin@Sun.COM shift 2 4628462SApril.Chin@Sun.COM done 4634887Schin (( 1.0/0.0 == Inf )) || err_exit '1.0/0.0 != Inf' 4648462SApril.Chin@Sun.COM [[ $(print -- $((0.0/0.0))) == ?(-)nan ]] || err_exit '0.0/0.0 != NaN' 4654887Schin (( Inf*Inf == Inf )) || err_exit 'Inf*Inf != Inf' 4664887Schin (( NaN != NaN )) || err_exit 'NaN == NaN' 4674887Schin (( -5*Inf == -Inf )) || err_exit '-5*Inf != -Inf' 4688462SApril.Chin@Sun.COM [[ $(print -- $((sqrt(-1.0)))) == ?(-)nan ]]|| err_exit 'sqrt(-1.0) != NaN' 4694887Schin (( pow(1.0,Inf) == 1.0 )) || err_exit 'pow(1.0,Inf) != 1.0' 4704887Schin (( pow(Inf,0.0) == 1.0 )) || err_exit 'pow(Inf,0.0) != 1.0' 4718462SApril.Chin@Sun.COM [[ $(print -- $((NaN/Inf))) == ?(-)nan ]] || err_exit 'NaN/Inf != NaN' 4724887Schin (( 4.0/Inf == 0.0 )) || err_exit '4.0/Inf != 0.0' 4734887Schinelse err_exit 'Inf and NaN not working' 4744887Schinfi 4758462SApril.Chin@Sun.COMunset x y n r 4768462SApril.Chin@Sun.COMn=14.555 4778462SApril.Chin@Sun.COMfloat x=$n y 4784887Schiny=$(printf "%a" x) 4798462SApril.Chin@Sun.COMr=$y 4808462SApril.Chin@Sun.COM[[ $r == $n ]] || err_exit "output of printf %a not self preserving -- expected $x, got $y" 4818462SApril.Chin@Sun.COMunset x y r 4828462SApril.Chin@Sun.COMx=-0 4838462SApril.Chin@Sun.COMy=$(printf "%g %g %g %g %g %g\n" -0. -0 $((-0)) x $x $((x))) 4848462SApril.Chin@Sun.COMr="-0 -0 -0 -0 -0 -0" 4858462SApril.Chin@Sun.COM[[ $y == "$r" ]] || err_exit "-0 vs -0.0 inconsistency -- expected '$r', got '$y'" 4868462SApril.Chin@Sun.COM$SHELL -c '(( x=));:' 2> /dev/null && err_exit '((x=)) should be an error' 4878462SApril.Chin@Sun.COM$SHELL -c '(( x+=));:' 2> /dev/null && err_exit '((x+=)) should be an error' 4888462SApril.Chin@Sun.COM$SHELL -c '(( x=+));:' 2> /dev/null && err_exit '((x=+)) should be an error' 4898462SApril.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' 49010898Sroland.mainz@nrubsig.org 49110898Sroland.mainz@nrubsig.orgfloat t 49210898Sroland.mainz@nrubsig.orgtypeset a b r 49310898Sroland.mainz@nrubsig.orgv="-0.0 0.0 +0.0 -1.0 1.0 +1.0" 49410898Sroland.mainz@nrubsig.orgfor a in $v 49510898Sroland.mainz@nrubsig.orgdo for b in $v 49610898Sroland.mainz@nrubsig.org do (( r = copysign(a,b) )) 49710898Sroland.mainz@nrubsig.org (( t = copysign(a,b) )) 49810898Sroland.mainz@nrubsig.org [[ $r == $t ]] || err_exit $(printf "float t=copysign(%3.1f,%3.1f) => %3.1f -- expected %3.1f\n" a b t r) 49910898Sroland.mainz@nrubsig.org done 50010898Sroland.mainz@nrubsig.orgdone 50110898Sroland.mainz@nrubsig.org 50210898Sroland.mainz@nrubsig.orgtypeset -l y y_ascii 50310898Sroland.mainz@nrubsig.org(( y=sin(90) )) 50410898Sroland.mainz@nrubsig.orgy_ascii=$y 50510898Sroland.mainz@nrubsig.org(( y == y_ascii )) || err_exit "no match,\n\t$(printf "%a\n" y)\n!=\n\t$(printf "%a\n" y_ascii)" 50610898Sroland.mainz@nrubsig.org 50710898Sroland.mainz@nrubsig.org( $SHELL <<- \EOF 50810898Sroland.mainz@nrubsig.org p=5 50910898Sroland.mainz@nrubsig.org t[p]=6 51010898Sroland.mainz@nrubsig.org while (( t[p] != 0 )) ; do 51110898Sroland.mainz@nrubsig.org (( 51210898Sroland.mainz@nrubsig.org p+=1 , 51310898Sroland.mainz@nrubsig.org t[p]+=2 , 51410898Sroland.mainz@nrubsig.org p+=3 , 51510898Sroland.mainz@nrubsig.org t[p]+=5 , 51610898Sroland.mainz@nrubsig.org p+=1 , 51710898Sroland.mainz@nrubsig.org t[p]+=2 , 51810898Sroland.mainz@nrubsig.org p+=1 , 51910898Sroland.mainz@nrubsig.org t[p]+=1 , 52010898Sroland.mainz@nrubsig.org p-=6 , 52110898Sroland.mainz@nrubsig.org t[p]-=1 52210898Sroland.mainz@nrubsig.org )) 52310898Sroland.mainz@nrubsig.org : 52410898Sroland.mainz@nrubsig.org done 52510898Sroland.mainz@nrubsig.orgEOF) 2> /dev/null || err_exit 'error with comma expression' 52610898Sroland.mainz@nrubsig.org 52710898Sroland.mainz@nrubsig.orgN=(89551 89557) 52810898Sroland.mainz@nrubsig.orgi=0 j=1 52910898Sroland.mainz@nrubsig.org[[ $(printf "%d" N[j]-N[i]) == 6 ]] || err_exit 'printf %d N[i]-N[j] failed' 53010898Sroland.mainz@nrubsig.org[[ $((N[j]-N[i])) == 6 ]] || err_exit '$((N[j]-N[i])) incorrect' 53110898Sroland.mainz@nrubsig.org 532*12068SRoger.Faulkner@Oracle.COMunset a x 533*12068SRoger.Faulkner@Oracle.COMx=0 534*12068SRoger.Faulkner@Oracle.COM((a[++x]++)) 535*12068SRoger.Faulkner@Oracle.COM(( x==1)) || err_exit '((a[++x]++)) should only increment x once' 536*12068SRoger.Faulkner@Oracle.COM(( a[1]==1)) || err_exit 'a[1] not incremented' 537*12068SRoger.Faulkner@Oracle.COMunset a 538*12068SRoger.Faulkner@Oracle.COMx=0 539*12068SRoger.Faulkner@Oracle.COM((a[x++]++)) 540*12068SRoger.Faulkner@Oracle.COM(( x==1)) || err_exit '((a[x++]++)) should only increment x once' 541*12068SRoger.Faulkner@Oracle.COM(( a[0]==1)) || err_exit 'a[0] not incremented' 542*12068SRoger.Faulkner@Oracle.COMunset a 543*12068SRoger.Faulkner@Oracle.COMx=0 544*12068SRoger.Faulkner@Oracle.COM((a[x+=2]+=1)) 545*12068SRoger.Faulkner@Oracle.COM(( x==2)) || err_exit '((a[x+=2]++)) should result in x==2' 546*12068SRoger.Faulkner@Oracle.COM(( a[2]==1)) || err_exit 'a[0] not 1' 547*12068SRoger.Faulkner@Oracle.COM 548*12068SRoger.Faulkner@Oracle.COMunset a i 549*12068SRoger.Faulkner@Oracle.COMtypeset -a a 550*12068SRoger.Faulkner@Oracle.COMi=1 551*12068SRoger.Faulkner@Oracle.COM(( a[i]=1 )) 552*12068SRoger.Faulkner@Oracle.COM(( a[0] == 0 )) || err_exit 'a[0] not 0' 553*12068SRoger.Faulkner@Oracle.COM(( a[1] == 1 )) || err_exit 'a[1] not 1' 554*12068SRoger.Faulkner@Oracle.COM 555*12068SRoger.Faulkner@Oracle.COMunset a 556*12068SRoger.Faulkner@Oracle.COMtypeset -i a 557*12068SRoger.Faulkner@Oracle.COMfor ((i=0;i<1000;i++)) 558*12068SRoger.Faulkner@Oracle.COMdo ((a[RANDOM%2]++)) 559*12068SRoger.Faulkner@Oracle.COMdone 560*12068SRoger.Faulkner@Oracle.COM(( (a[0]+a[1])==1000)) || err_exit '(a[0]+a[1])!=1000' 561*12068SRoger.Faulkner@Oracle.COM 5624887Schinexit $((Errors)) 563