Zsh Mailing List Archive
Messages sorted by:
Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)
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))'
zira% zsh -fc 'export LC_ALL=tr_TR.utf8; echo $((Inf)) $((inf))'
zira% ksh93 -fc 'export LC_ALL=fr_FR.utf8; echo $((Inf)) $((inf))'
zira% ksh93 -fc 'export LC_ALL=tr_TR.utf8; echo $((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
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)
Messages sorted by: