Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: inf and nan in arithmetic expansions
- X-seq: zsh-workers 42353
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- Subject: Re: inf and nan in arithmetic expansions
- Date: Fri, 09 Feb 2018 15:31:12 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=0r58IF WBQ47hnIsGrfcn9CjOmu7Q8/86Mu4nKAO/WjI=; b=VVIwgm903V3ymxRCxwWX/6 /NW/MKYuFA0RMwQMQDlUa6Vv/sIRnBwvF0jfgZygNBxNmZBaDzeTgeOxmkIqwzxq 8DCCg/LheF6obtb+EO+htcZD5w3u+O1xG8vsbf1t6G8GJYEOtaYCwdhx+5y9MypO OcNzPCj+K28VqWv2U71K64GL74yHI4YvmHka/h5v0PMUX6A9Oq+/995ExuZ7Q0WW XbxynHdO7OmdQJbImR/uhVv6qbH0FP7k+FSfHqNJFgfooO6HiZmimBV2rcLzH0j+ mA9snW9tGP7bhLdlUcxkbGdQ7yaq7Rr7CW43CXX0JoFhmhW+py5WTx/aGqY9FhSw ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=0r58IF WBQ47hnIsGrfcn9CjOmu7Q8/86Mu4nKAO/WjI=; b=jkA7thjc8QarHSL0pajNXi F8FwnNns8LT/MNoUPQMLRADwn72rpg3+jqgJykunlDykcFAHKBIH95cKFyTKi9P1 ZL39nwd2BWgZXH7c0+z0NOgLvKEHXLWaUYapzdQKP9Ent2DQZuYL5hbaPi2gjKf1 3ZZWFYjsBldIQ660xtI1Tj5rKhom2OjTXqdi7CqTwx1yJQ1R3EGcYy2+5HReXEY1 fOHtTlLTX7R8jVv1/FDjATV9tx1o0dpvu9+vHJ3LPQI4UCp+q++ReXxP0TB08LiN xx2KIjqu1UzVLQTnw4bY+Od5PfeIc46d8b2ya8BXwsvvk1q+Q2ezManpxi7oZGJw ==
- In-reply-to: <20180208142211.GA14888@chaz.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20180207223051.GA30393@chaz.gmail.com> <4253.1518045946@thecus.kiddle.eu> <1518093995.645366.1263935336.265ED7BF@webmail.messagingengine.com> <20180208142211.GA14888@chaz.gmail.com>
Stephane Chazelas wrote on Thu, 08 Feb 2018 14:22 +0000:
> 2018-02-08 12:46:35 +0000, Daniel Shahaf:
> > 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...
>
> But what value would you use for those variables?
'inf' would be positive infinity. 'nan' would be a NaN (whichever flavour
thereof would be least surprising).
> Or do you mean that the shell arithmetic parser would understand
> "inf"/"nan" as the infinity and not-a-number numbers and not as the
> variable (otherwise with inf=inf, that would do infinite recursion)
Why would it be recursive?
> but just make inf/nan readonly so users not be tempted to use them as
> variables?
That would be the simplest implementation, yes. It might suffice, or we might
prefer something more elaborate.
> I'd also rather "inf" be used instead of "inf." (would also
> align with ksh93), but the change could potentially break some
> scripts. If we also make $inf/$nan read-only variables, that
> would also break scripts that use $inf/$nan variables but not
> in arithmetic contexts (like for inf in *.inf), so that doesn't
> sound like a good idea to me.
Yes, that would be backwards incompatible. If we choose this path,
those people can use 'for inf in...' use 'local inf' or 'local -h inf'
to hide the float inf/nan.
One option that is compatible is to make 'inf' and 'nan' only declared
on an opt-in basis --- using some autoload/zmodload, or perhaps with
some "This script requires zsh 5.5 or greater" directive.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author