$w = [ map { my $v = $f + $s*$_/$i; $f = $v - int($v); $v # not int $v } @$w ]; $w->[-1] += $f;