zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: zsh-workers@zsh.org
Subject: Re: inf and nan in arithmetic expansions
Date: Mon, 19 Feb 2018 14:19:15 +0000	[thread overview]
Message-ID: <20180219141915.GA9833@chaz.gmail.com> (raw)
In-Reply-To: <1518827932.2163403.1273708688.6920FBA8@webmail.messagingengine.com>

2018-02-17 00:38:52 +0000, Daniel Shahaf:
> Oliver Kiddle wrote on Fri, 16 Feb 2018 17:51 +0100:
> > > And then we could add 'inf' and 'nan' as readonly variables initialised to
> > > those respective values (as Oliver also suggests in the 19597 thread).  There
> > > are compatibility implications for scripts that use these variable names, but
> > > there is no way around them if we want to allow explicitly doing (( x = inf ))
> > > in user code...
> > 
> > I'm not sure about making them readonly simply because not doing so is
> > less likely to break an existing script.
> 
> After 42356 I am not sure whether I would prefer predefined variables
> (readonly or not) or recognising 'inf' and 'nan' (putting aside the
> question of case for a moment) as special constants in math contexts
> as 42356 suggests.
[...]

A note on top of what I said earlier on that. In ksh93, from a
syntax point of view, it does look a bit like ksh93 treats
"inf"/"nan" (with any variation of case) like if it was a
variable whose value resolved to infinity as seen when we use
inf[0] (but not ${inf[0]}) in arithmetic contexts:

$ ksh93 -c 'InF=(2 3); echo "$((InF[0])) $((${InF[0]}))"'
inf 2

Or with:

$ ksh93 -c 'inf=2; echo "$((inf = 1, inf))"'
ksh93: Inf: is read only

But:

$ ksh93 -c 'echo "$((${Inf=2}))"'
2
$ ksh93 -c 'echo "$((${Inf=2}, Inf))"'
inf

That does look bad to me.

I still think it doesn't make sense to treat inf/nan as
variables.

-- 
Stephane


  reply	other threads:[~2018-02-19 14:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-07 22:30 Stephane Chazelas
2018-02-07 23:25 ` Oliver Kiddle
2018-02-08  9:38   ` Peter Stephenson
2018-02-08 12:46   ` Daniel Shahaf
2018-02-08 14:22     ` Stephane Chazelas
2018-02-09 15:31       ` Daniel Shahaf
2018-02-09 21:09         ` Stephane Chazelas
2018-02-10  0:10           ` Bart Schaefer
2018-02-16 16:51     ` Oliver Kiddle
2018-02-17  0:38       ` Daniel Shahaf
2018-02-19 14:19         ` Stephane Chazelas [this message]
2018-02-27 13:02       ` Vincent Lefevre
2018-02-27 15:25         ` Oliver Kiddle
2018-02-27 16:56           ` Vincent Lefevre
2018-03-21 23:46       ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180219141915.GA9833@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).