zsh-workers
 help / color / mirror / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions)
Date: Fri, 23 Apr 2021 13:31:29 -0700
Message-ID: <CAH+w=7ZMWJjB_tnGHW7kvkMr8MO4QQXuobjRMQeyxmTcK4fbyw@mail.gmail.com> (raw)
In-Reply-To: <20210423164525.GA2033191@zira.vinc17.org>

On Fri, Apr 23, 2021 at 9:46 AM Vincent Lefevre <vincent@vinc17.net> wrote:
>
> On 2021-04-22 11:55:25 -0700, Bart Schaefer wrote:
> > On Thu, Apr 22, 2021 at 8:31 AM Vincent Lefevre <vincent@vinc17.net> wrote:
> > >
> > > IMHO, zsh should also output a warning when such variables are used.
> >
> > Exactly how would that work?
>
> When inf or nan is used in a math context and the corresponding
> variable exists.

So, it's the "expend effort on a check that is nearly always going to
fail" option.

Not advocating for the below patch, just providing for reference.
gmail may have munged tabs causing indentation to look funny.

diff --git a/Src/math.c b/Src/math.c
index 1d0d86639..50c34416d 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -865,12 +865,22 @@ zzlex(void)
         ptr = ie;
         if (ie - p == 3) {
             if (strncasecmp(p, "NaN", 3) == 0) {
+                char iec = *ie; *ie = 0;
+            if (issetvar(p)) {
+                zwarn("%s: using constant NaN", p);
+            }
+            *ie = iec;
             yyval.type = MN_FLOAT;
             yyval.u.d = 0.0;
             yyval.u.d /= yyval.u.d;
             return NUM;
             }
             else if (strncasecmp(p, "Inf", 3) == 0) {
+                char iec = *ie; *ie = 0;
+            if (issetvar(p)) {
+                zwarn("%s: using constant Inf", p);
+            }
+            *ie = iec;
             yyval.type = MN_FLOAT;
             yyval.u.d = 0.0;
             yyval.u.d = 1.0 / yyval.u.d;
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index d0092fefa..e6333890c 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -306,17 +306,22 @@
   in=1 info=2 Infinity=3 Inf=4
   print $(( in )) $(( info )) $(( Infinity )) $(( $Inf )) $(( inf ))
$(( INF )) $(( Inf )) $(( iNF ))
 0:Infinity parsing
+?(eval):2: Inf: using constant Inf
 >1 2 3 4 Inf Inf Inf Inf

   integer Inf
   print $(( Inf[0] ))
 1:Refer to Inf with an array subscript
+?(eval):2: Inf: using constant Inf
 ?(eval):2: bad base syntax

+  integer NaN
   (( NaN = 1 ))
 2:Assign to NaN
-?(eval):1: bad math expression: lvalue required
+?(eval):2: NaN: using constant NaN
+?(eval):2: bad math expression: lvalue required

+  unset Inf
   a='Inf'
   (( b = 1e500 ))
   print $((1e500)) $(($((1e500)))) $(( a )) $b $(( b )) $(( 3.0 / 0 ))


  reply	other threads:[~2021-04-23 20:32 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-10 23:31 [PATCH] Document imperfections in POSIX/sh compatibility dana
2021-04-10 23:50 ` Bart Schaefer
2021-04-11  0:19   ` dana
2021-04-11 16:54     ` Bart Schaefer
2021-04-11 17:57       ` sh emulation POSIX non-conformances (Was: [PATCH] Document imperfections in POSIX/sh compatibility) Stephane Chazelas
2021-04-11 18:13         ` Bart Schaefer
2021-04-11 19:18         ` sh emulation POSIX non-conformances (no word splitting upon arithmetic expansion) Stephane Chazelas
2021-04-22 15:03           ` Vincent Lefevre
2021-04-22 18:27             ` Bart Schaefer
2021-04-11 19:31         ` sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions) Stephane Chazelas
2021-04-12 20:41           ` Bart Schaefer
2021-04-13  7:17             ` Stephane Chazelas
2021-04-22 15:31               ` Vincent Lefevre
2021-04-22 18:55                 ` Bart Schaefer
2021-04-22 20:45                   ` Daniel Shahaf
2021-04-22 21:25                     ` Bart Schaefer
2021-04-23 16:45                   ` Vincent Lefevre
2021-04-23 20:31                     ` Bart Schaefer [this message]
2021-04-23 22:46                       ` Oliver Kiddle
2021-04-23 23:34                         ` Bart Schaefer
2021-04-24  2:10                           ` Daniel Shahaf
2021-04-24  3:42                             ` Bart Schaefer
2021-04-24  7:33                               ` Stephane Chazelas
2021-04-24 16:04                                 ` Bart Schaefer
2021-04-24 23:02                         ` Vincent Lefevre
2021-04-25  2:18                           ` Bart Schaefer
2021-04-25 20:17                             ` Vincent Lefevre
2021-04-25 21:58                               ` Bart Schaefer
2021-04-26 10:28                                 ` Vincent Lefevre
2021-04-25 22:00                               ` Bart Schaefer
2021-04-26 10:34                                 ` Vincent Lefevre
2021-04-26 23:25                                   ` Vincent Lefevre
2021-04-11 19:33         ` sh emulation POSIX non-conformances (some of zsh's special variables) Stephane Chazelas
2021-04-11 19:42         ` sh emulation POSIX non-conformances (printf %10s and bytes vs character) Stephane Chazelas
2021-04-13 15:57           ` Daniel Shahaf
2021-04-13 18:03             ` Stephane Chazelas
2021-04-13 21:09               ` Bart Schaefer
2021-04-22 13:59           ` Vincent Lefevre
2021-04-22 14:28             ` Vincent Lefevre
2021-04-22 19:22             ` Bart Schaefer
2021-04-23 16:53               ` Vincent Lefevre
2021-04-23 23:01                 ` Oliver Kiddle
2021-04-24 21:41                   ` Vincent Lefevre
2021-04-24 21:46                   ` Vincent Lefevre
2021-04-24  7:09                 ` Stephane Chazelas
2021-04-24 21:52                   ` Vincent Lefevre
2021-04-24 22:28                     ` Bart Schaefer
2021-04-24 23:18                       ` Vincent Lefevre
2021-04-25  2:20                         ` Bart Schaefer
2021-04-25 11:07                           ` Vincent Lefevre
2021-04-11 23:04       ` [PATCH] Document imperfections in POSIX/sh compatibility dana
2021-04-13 16:01 ` Daniel Shahaf
2021-04-13 16:12   ` Peter Stephenson
2021-04-13 20:28   ` Oliver Kiddle
2021-04-13 21:40     ` dana
2021-04-13 22:02       ` Bart Schaefer
2021-04-14 12:38       ` Daniel Shahaf
2021-04-18  4:50         ` dana
2021-04-20 21:26           ` Daniel Shahaf
2021-05-03 23:42             ` dana

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='CAH+w=7ZMWJjB_tnGHW7kvkMr8MO4QQXuobjRMQeyxmTcK4fbyw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --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

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git