Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zmathfunc: min, max, sum throw error if result equals 0
- X-seq: zsh-workers 48602
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: zmathfunc: min, max, sum throw error if result equals 0
- Date: Fri, 16 Apr 2021 18:26:04 +0000
- Archived-at: <https://zsh.org/workers/48602>
- In-reply-to: <CAH+w=7ZFbOJc16r6JX4Lr6uPdVRji_=RmY3WZVBK9GtXzxjPmA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <m2pn0aj4y2.fsf@zaclys.net> <20210307171712.GA9936@tarpaulin.shahaf.local2> <CAH+w=7bPz5u9-mQPbmPmbo=8Cz8em7JmbSn-sp8eZzuvFW3mnQ@mail.gmail.com> <ee7c107d-8bfb-4063-85e8-a7638ae0f951@www.fastmail.com> <CAH+w=7ZFbOJc16r6JX4Lr6uPdVRji_=RmY3WZVBK9GtXzxjPmA@mail.gmail.com>
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
- References:
- zmathfunc: min, max, sum throw error if result equals 0
- Re: zmathfunc: min, max, sum throw error if result equals 0
- Re: zmathfunc: min, max, sum throw error if result equals 0
- Re: zmathfunc: min, max, sum throw error if result equals 0
- Re: zmathfunc: min, max, sum throw error if result equals 0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author