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 Thu, Apr 22, 2021 at 11:55:25 -0700:
> On Thu, Apr 22, 2021 at 8:31 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> >
> > On 2021-04-13 08:17:42 +0100, Stephane Chazelas wrote:
> > > I think it would be worth documenting that nan and inf are
> > > recognised in arithmetic expressions (and warn against using
> > > variables with the same name).
> >
> > IMHO, zsh should also output a warning when such variables are used.
>
> Exactly how would that work?
>
> Warning anytime the names "inf" or "nan" (and case variants) get
> values assigned to them seems like overkill.
>
Warn only when the variable is created, e.g., upon «typeset -F inf» or
«(( nan = 3.14 ))», but not subsequent assignments?
> If they appear as $inf or $nan then there's no conflict. Still warn?
No, I guess? No one expects «$42» and «42» to mean the same thing, nor
«$0.0» and «0.0».
> If "inf" and "nan" appear in math context as the bare strings they're
> currently taken as constants. Always make a (usually
> wasted/fruitless) check to see whether there happens to be a variable
> of the same name and emit a "watch out, not used" message?
No; optimize for the common case that $inf and $nan don't exist.
Warning upon creation of those suffices.
>
Predefine $inf and $nan as readonly float variables initialized to the
respective values? (Not saying this is a good idea; just mentioning it
for completeness)
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author