zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [BUG] POSIX arith: inf, nan should be variables
Date: Mon, 15 Nov 2021 18:40:17 +0100	[thread overview]
Message-ID: <f45c480a-a7ac-54fc-4140-665ff98f9dc6@inlv.org> (raw)

$ zsh --emulate sh -c 'inf=1; nan=2; echo $((inf)) $((nan))'
Inf NaN

Expected: 1 2

This is a POSIX compliance issue that ksh93 also has (I've just fixed in 
ksh 93u+m). I can see why this is needed for full floating point 
arithmetic support, but in POSIX sh, all case variants of inf and nan 
are perfectly legitimate variables that portable scripts should be able 
to use, including in arithmetic evaluation. Their recognition should be 
turned off for sh emulation, but not for ksh emulation as ksh93's native 
mode also supports floating point arithmetic.

So, what shell option to tie that to? That's a bit difficult. It needs 
to be an option that is on for sh, but off for ksh (or vice versa). A 
comparison of 'set -o' output between sh and ksh modes shows that the 
options are limited to the following:

bsdecho
ignorebraces
kshglob
kshoptionprint
localoptions
localtraps
octalzeroes
promptbang
sharehistory
singlelinezle

The only one of those that has anything to do with an arithmetic context 
is octalzeroes, so that one may be the least bad one to choose. The 
preliminary patch below does that.

Perhaps octalzeroes could be renamed to something like posixmath, so 
that it becomes legitimate to attach this and any other POSIX arithmetic 
quirks to this option without further crowding the shell option space.

Thoughts/opinions?

--- a/Src/math.c
+++ b/Src/math.c
@@ -863,7 +863,7 @@ zzlex(void)

  		p = ptr;
  		ptr = ie;
-		if (ie - p == 3) {
+		if (ie - p == 3 && !isset(OCTALZEROES)) {
  		    if ((p[0] == 'N' || p[0] == 'n') &&
  			(p[1] == 'A' || p[1] == 'a') &&
  			(p[2] == 'N' || p[2] == 'n')) {

-- 
||	modernish -- harness the shell
||	https://github.com/modernish/modernish
||
||	KornShell lives!
||	https://github.com/ksh93/ksh


             reply	other threads:[~2021-11-15 17:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 17:40 Martijn Dekker [this message]
2021-11-16  9:06 ` Oliver Kiddle
2021-11-16 12:55 ` Vincent Lefevre
2021-11-28 20:34   ` Oliver Kiddle
2021-12-01  3:31     ` Daniel Shahaf
2021-12-01  3:37       ` Bart Schaefer
2021-12-01  4:27         ` Writing XFail tests (was: Re: [BUG] POSIX arith: inf, nan should be variables) Daniel Shahaf

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=f45c480a-a7ac-54fc-4140-665ff98f9dc6@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    --subject='Re: [BUG] POSIX arith: inf, nan should be variables' \
    /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

Code repositories for project(s) associated with this 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).