*X-seq*: zsh-workers 48697*From*: Vincent Lefevre <vincent@xxxxxxxxxx>*To*: zsh-workers@xxxxxxx*Subject*: Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)*Date*: Sun, 25 Apr 2021 01:02:19 +0200*Archived-at*: <https://zsh.org/workers/48697>*In-reply-to*: <55222-1619218004.791735@3FXq.NU49.vlrg>*List-id*: <zsh-workers.zsh.org>*Mail-followup-to*: zsh-workers@xxxxxxx*References*: <CAH+w=7a6sjNJsDv4KJyW-o45+Q7GNEp7_TL4LGd-os1ozF8T9A@mail.gmail.com> <20210411175726.hxnm33mxoska2tsm@chazelas.org> <20210411193154.zkekzvb4o6xmriwo@chazelas.org> <CAH+w=7aAeEMDJX9q4M9jvb0Z8nhYuOdHRk_N4KS91yKP5B5eLQ@mail.gmail.com> <20210413071742.tisslgg5fdqbageg@chazelas.org> <20210422153100.GD154089@zira.vinc17.org> <CAH+w=7a2XgrCqYAuDD4QYm7DBnNsshZQN6MazEVL0L-wngLTZg@mail.gmail.com> <20210423164525.GA2033191@zira.vinc17.org> <CAH+w=7ZMWJjB_tnGHW7kvkMr8MO4QQXuobjRMQeyxmTcK4fbyw@mail.gmail.com> <55222-1619218004.791735@3FXq.NU49.vlrg>

On 2021-04-24 00:46:44 +0200, Oliver Kiddle wrote: > Bart Schaefer wrote: > > On Fri, Apr 23, 2021 at 9:46 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote: > > > > > IMHO, zsh should also output a warning when such variables are used. > > I disagree. We also have variables named 0, 1, 2, 3 and so on - the > positional parameters. But nobody would suggest warning about literal > value 7 in maths context. This is different: the digits are already used in integers, and the behavior is the same in all shells. > > So, it's the "expend effort on a check that is nearly always going to > > fail" option. > > I can just about see the case for warning on typeset -i/-F inf or nan > but not on use. The traditional Unix approach is not to stop people who > choose to shoot themselves in the foot. In a maths expression, you're > going to end up with inf, -inf or nan as your result anyway so it > quickly becomes fairly obvious what is going on. People could waste a lot of time finding what is going on, in particular those who don't use floating point at all. > If we're worrying about POSIX compliance, it'd be easy enough to disable > Inf and NaN in POSIX mode but there are dozens of special variables > defined that aren't in the POSIX spec either and which could clash. However, it is a bit easier to see what is going on with special variables. And they have been documented for a long time. On the opposite, the zsh manual (for 5.8) is silent on Inf and NaN. And both for the behavior and documentation, be careful with the locales, in particular in Turkish ones. I don't know whether this is expected in zsh, but... zira% zsh -fc 'export LC_ALL=fr_FR.utf8; echo $((Inf)) $((inf))' Inf Inf zira% zsh -fc 'export LC_ALL=tr_TR.utf8; echo $((Inf)) $((inf))' Inf 0 With ksh93: zira% ksh93 -fc 'export LC_ALL=fr_FR.utf8; echo $((Inf)) $((inf))' inf inf zira% ksh93 -fc 'export LC_ALL=tr_TR.utf8; echo $((Inf)) $((inf))' inf inf > It is generally helpful to be able to re-input the output as input > in a later line of code. Even with the POSIX behavior, a problem is unlikely to occur, because zsh uses a mix of uppercase and lowercase letters, and this is uncommon in variable names. Moreover, if people get Inf or NaN in their computation, I doubt that they would use such variable names. -- Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

**Follow-Ups**:**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Bart Schaefer

**References**:**Re: [PATCH] Document imperfections in POSIX/sh compatibility***From:*Bart Schaefer

**sh emulation POSIX non-conformances (Was: [PATCH] Document imperfections in POSIX/sh compatibility)***From:*Stephane Chazelas

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Stephane Chazelas

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Bart Schaefer

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Stephane Chazelas

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Vincent Lefevre

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Bart Schaefer

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Vincent Lefevre

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Bart Schaefer

**Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)***From:*Oliver Kiddle

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