*X-seq*: zsh-workers 48681*From*: Oliver Kiddle <opk@xxxxxxx>*To*: Zsh hackers list <zsh-workers@xxxxxxx>*Subject*: Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)*Date*: Sat, 24 Apr 2021 00:46:44 +0200*Archived-at*: <https://zsh.org/workers/48681>*In-reply-to*: <CAH+w=7ZMWJjB_tnGHW7kvkMr8MO4QQXuobjRMQeyxmTcK4fbyw@mail.gmail.com>*List-id*: <zsh-workers.zsh.org>*References*: <7FD930F4-37CD-402B-9A06-893818856199@dana.is> <CAH+w=7aAZKpT0f5LT7RaoCehyO6UZe6FimzuQqOP4o=+EwZs2w@mail.gmail.com> <F56FD538-0428-4D03-BBE2-6E53154EC0EA@dana.is> <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>

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. > 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. 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. While @inf would have avoided clashing with the variable, I've not seen any other language which does that and consistency makes it easier. The shell is one language where special characters should be especially avoided because it is used interactively. Not everyone has a US-layout keyboard and @ is often in weird places. It'd also raise the question of what we should output. printf should follow the standard. Note that in bash (and quite a few other implementations): printf '%f\n' inf inf It is generally helpful to be able to re-input the output as input in a later line of code. > + if (issetvar(p)) { > + zwarn("%s: using constant NaN", p); I'm not sure that "constant" is even the correct term for what NaN or even Inf is? Note that NaN == NaN is, by definition, false. For an accurate description perhaps check IEEE754 but it is more along the lines of being an intrinsic literal value. > integer Inf > print $(( Inf[0] )) > 1:Refer to Inf with an array subscript That could potentially be made to work as an array lookup because subscripts have no other meaning that would clash. Oliver

**Follow-Ups**:**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

**References**:**[PATCH] Document imperfections in POSIX/sh compatibility***From:*dana

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

**Re: [PATCH] Document imperfections in POSIX/sh compatibility***From:*dana

**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

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