On Sun, Apr 21, 2013 at 4:20 PM, Roland Mainz <[email protected]> wrote:
> On Sun, Apr 21, 2013 at 3:21 PM, Roland Mainz <[email protected]> 
> wrote:
>> Another "typeset -m" issue... the following example doesn't work if
>> function "sortar" is declared using "function sortar" instead of
>> "sortar():
>> -- snip --
[snip]
>> -- snip --
>
> Here's an updated version of the testcase which handles the
> floating-point corner issues of { -nan/+nan, -inf, +inf }:
> -- snip --
> function sortar
> #sortar()
> {
>         nameref         ar=$1
>         bool            direction=$2
>         integer         i
>         integer -r      i_max=${#ar[@]}
>         float           d
>         bool            swapped=true
>         (( d=direction?+1.:-1. ))
>
>         while $swapped ; do
>                 swapped=false
>                 for (( i=1 ; i < i_max ; i++ )) ; do
>                         if (( isnan(ar[i].i) ||
>                                 isgreater((ar[i].i - ar[i-1].i)*d, 0.)
>                                 )) ; then
>                                 typeset -m "tmp=ar[i-1]"
>                                 typeset -m "ar[i-1]=ar[i]"
>                                 typeset -m "ar[i]=tmp"
>                                 swapped=true
>                         fi
>                 done
>         done
>         return 0
> }
>
> function main
> {
>         compound c=(
>                 compound -a ar=(
>                         ( float i=4 )
>                         ( float i=2 )
>                         ( float i=-nan )
>                         ( float i=2 )
>                         ( float i=-inf )
>                         ( float i=1 )
>                         ( float i=24 )
>                         ( float i=+inf )
>                         ( float i=-1 )
>                 )
>         )
>
>         sortar c.ar true
>
>         print -v c
> }
>
> # main
> set -o nounset
> main
> -- snip --
>
> AFAIK it should print:
> -- snip --
> $ ksh sortc.sh
> (
>         typeset -C -a ar=(
>                 [0]=(
>                         typeset -l -E i=-nan
>                 )
>                 [1]=(
>                         typeset -l -E i=inf
>                 )
>                 [2]=(
>                         typeset -l -E i=24
>                 )
>                 [3]=(
>                         typeset -l -E i=4
>                 )
>                 [4]=(
>                         typeset -l -E i=2
>                 )
>                 [5]=(
>                         typeset -l -E i=2
>                 )
>                 [6]=(
>                         typeset -l -E i=1
>                 )
>                 [7]=(
>                         typeset -l -E i=-1
>                 )
>                 [8]=(
>                         typeset -l -E i=-inf
>                 )
>         )
> )
> -- snip --
> ... but ast-ksh.2013-04-09 on SuSE 12.2/AMD64/64bit prints this:
> -- snip --
> $ ksh sortc.sh
> sortc.sh[53]: main[46]: sortar: line 18: ar[i-1].i)*d, 0.)
>                                 : parameter not set
> (
>         typeset -C -a ar=(
>                 [0]=(
>                         typeset -l -E i=4
>                 )
>                 [1]=(
>                         typeset -l -E i=-nan
>                 )
>                 [3]=(
>                         typeset -l -E i=2
>                 )
>                 [4]=(
>                         typeset -l -E i=-inf
>                 )
>                 [5]=(
>                         typeset -l -E i=1
>                 )
>                 [6]=(
>                         typeset -l -E i=24
>                 )
>                 [7]=(
>                         typeset -l -E i=inf
>                 )
>                 [8]=(
>                         typeset -l -E i=-1
>                 )
>         )
> )
> -- snip --

(note: +0./-0. are _not_ sorted according to their sign - see
http://en.wikipedia.org/wiki/Signed_zero#Comparisons)

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to