*X-seq*: zsh-workers 31353*From*: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>*To*: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>, "Zsh Hackers' List" <zsh-workers@xxxxxxx>*Subject*: Re: [bug] $((0.5?1+1:3))*Date*: Sun, 28 Apr 2013 21:15:42 -0700*In-reply-to*: <20130429020002.GA7626@chaz.gmail.com>*List-help*: <mailto:zsh-workers-help@zsh.org>*List-id*: Zsh Workers List <zsh-workers.zsh.org>*List-post*: <mailto:zsh-workers@zsh.org>*Mailing-list*: contact zsh-workers-help@xxxxxxx; run by ezmlm*References*: <20130429020002.GA7626@chaz.gmail.com>

On Apr 29, 3:00am, Stephane Chazelas wrote: } } That's quite an odd one. For any value of x between -1 and 1 } (-1, 1 and 0 excluded), $(( x ? <some-expression> : 42 )) where } <some-expression> is anything but a numeric constant, expands to } "0". Hrm. In math.c around line 1398 (varies a lot by version of zsh) we have the "case QUEST:" that handles ternary expressions. There we find this: q = (stack[sp].val.type == MN_FLOAT) ? (zlong)stack[sp].val.u.d : stack[sp].val.u.l; Note this is rouding q down to an integer, so fractions less than one are false. This is followed by: if (!q) noeval++; mathparse(prec[COLON] - 1); if (!q) noeval--; So the expression is consumed without parsing it. This "works" for contatants by accident. Later when parsing is complete and the correct non-zero-ness of the fraction is determined, the value of the unparsed expression is substituted, which is almost always zero. This should do it: diff --git a/Src/math.c b/Src/math.c index a2462a3..5bd4b90 100644 --- a/Src/math.c +++ b/Src/math.c @@ -1459,7 +1459,8 @@ mathparse(int pc) case QUEST: if (stack[sp].val.type == MN_UNSET) stack[sp].val = getmathparam(stack + sp); - q = (stack[sp].val.type == MN_FLOAT) ? (zlong)stack[sp].val.u.d : + q = (stack[sp].val.type == MN_FLOAT) ? + (stack[sp].val.u.d == 0 ? 0 : 1) : stack[sp].val.u.l; if (!q)

**References**:**[bug] $((0.5?1+1:3))***From:*Stephane Chazelas

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