Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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



On 2021-04-13 08:17:42 +0100, Stephane Chazelas wrote:
> 2021-04-12 13:41:58 -0700, Bart Schaefer:
> > On Sun, Apr 11, 2021 at 12:32 PM Stephane Chazelas
> > <stephane@xxxxxxxxxxxx> wrote:
> > >
> > > $ zsh --emulate sh -c 'inf=42; echo $((inf))'
> > > Inf
> > >
> > > (POSIX requires 42 there).
> > 
> > Is that because "Inf" is case-sensitive, or because POSIX requires
> > evaluating the variable?  E.g. what does
> 
> That was because "inf" in an arithmetic expression, where inf is
> the name of a variable whose contents is an integer constant
> (decimal, octal or hex) is meant to represent the corresponding
> integer number (and an empty or unset variable is meant to yield
> 0)..

I think that it would have been better if zsh chose something that
does not correspond to the name of a variable, e.g. @Inf@ and @NaN@
(this is what MPFR does, so that it cannot be confused with numbers
in large bases, where letters are used as digits).

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

-- 
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: Reverse Date, Date, Thread, Author