Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zmathfunc: min, max, sum throw error if result equals 0



Bart Schaefer wrote on Sun, Mar 07, 2021 at 18:25:00 -0800:
> On Sun, Mar 7, 2021 at 1:57 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> > Bart Schaefer wrote on Sun, 07 Mar 2021 21:39 +00:00:
> > > zsh_math_func_min() {
> > >   local result=$(( $1 ))
> >
> > Doesn't this still do multiple string-to-number conversions?
> 
> I don't think so ... the $(( ... )) should turn $1 into a single
> number assigned to result.  What are you thinking about?

When «$foo» appears inside «$((…))», it's expanded as a string that's
then parsed as math.  The result of «$((…))» is then assigned to the
$result, which is eventually used as «(( result ))», where — because
${(t)result} is non-integer scalar — there will be another
string-to-integer conversion.

Sorry for the delay on this.

Daniel




Messages sorted by: Reverse Date, Date, Thread, Author