Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author