From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6516 invoked from network); 23 Apr 2021 20:32:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Apr 2021 20:32:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1619209922; b=Kbk7OVbBrJjkc/XA2X0sofkyrT1g1YTCISWCRsdSY6sav9qiiiifyCoKmVhtjhLy1imPIUplJ9 Swk+fhphwXRcanFoBhWPyYbdEZv/5XcJjXArrR+8H43tPyI2mToGyDN3ygF+e31TtFLxOtudJx 6txYth96NJW/Z6Ligm0NANLtG6EAb5P+SHM3g6jVI/Z+gACkQA6a4iMinivt/vk8dI3K0Y3D36 UIdRDRTMOhhlw8SEYOILVLJDV7r6yYW9RMb30BU+Zp/C1NKYD3L+BDzXclGNqf/irY7JBUCdL9 aXlPzezYupAC4EwE908B2La8pi0T2WWdkFM30WTrMGixQA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oo1-f52.google.com) smtp.remote-ip=209.85.161.52; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1619209922; bh=LqHskSlnxRHqmhCGhwm3usXg3Tk8pUvJ5HapPKsej+w=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=u7BWYljEBmFOdykDLw/pkhQZpQvO7Iiij+mI7oeGc2+PuOipnOF8IoBds6kdvjxGAq1S5ox0vR iSBsYrQOtjNam4Y4BRvxGT9SWFtxanZGtarjtZXcbPbAv2ZkTFaenNAYKyMU2Ab8PwWHkwaDTH 5KbJFCNQqDZWVx7qzQKvYSsKgpr/uu8abLZxYGPt/mtxJ0N1Pimy7nmnmbqkH2vFrrQtd67d+i R4znNU59z8WSriylPugxPZBhnLvMzcikFvl01uUbPTk/SuhYm7Wzx7FmJOvv8IBEotJJNsk7Qh J8HCWfmgFS5F1MqLYf7/IoORk8Secvume5gLv4U4xbXGjw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=eJdcn6VolWZ8agRzMDla+/2UdEjq3kJCzEhhmyXUnMk=; b=dD0WhJGPeQFG38fthPw40cB/XT XhohFQrMpOLhyaPWQDK1fMZHBqKJlVVWftWIDZXzaZ/G2nmLCKPM0eE2MUZJKQUbF2GuoHbHaTzgx 28GTmUb0OJdtPo2xNdlLuaJd2Xa09LA4T15zC0GnWb85l+0NWde1K9BhxM6G7rZqgRx4nVPxj4V8k BVPkLQD4ywH7u6XDh5PfBTTkpKRARRDzPBWV8LI8elYWQZDoP46IhBiX6vLHos8xB6wpq+6m8Xmeu +xgTYJhKlxjknRRbN+z0UVKvxXKkb3olxMD4tpDx5tyMkP+r88goek29G9NAvmwKcroOjx+Am5Z7Z 2UvWjSvA==; Received: from authenticated user by zero.zsh.org with local id 1la2T3-000DOC-Ar; Fri, 23 Apr 2021 20:32:01 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oo1-f52.google.com) smtp.remote-ip=209.85.161.52; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oo1-f52.google.com ([209.85.161.52]:41920) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1la2Sk-000D79-OQ; Fri, 23 Apr 2021 20:31:44 +0000 Received: by mail-oo1-f52.google.com with SMTP id d16-20020a4a3c100000b02901f0590a614eso3109866ooa.8 for ; Fri, 23 Apr 2021 13:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=eJdcn6VolWZ8agRzMDla+/2UdEjq3kJCzEhhmyXUnMk=; b=U8vQzZYpeyD2meto66Y0TNCDi5BObYy0Qd1dUM4SsbuDF19X6Ue/4eZPFdjslM8MLG kxYrzPPAo/B8tFRKIxRmfVrW1REU+oiNZ0vy7M0ruB1H7PTRKezgVyX9ggg+reX7GkjS u1t2bHwGDGDOYSZJx0gigZc1+SQpmgHoTFZXaAoSzE7medTdYClPoTOQO8mOiwPDUtni 6H4mLaP08j/I2uFew/z56+SPyil5IW6vmT6kkBPU23QMB1dIfAleMQIGimHb0GuOili9 BO0N1Q3FUwpEbYOrhP2/OGngN/BTCh2bClaUB7EQU/dfwho3BqN5JzVSRFJrfFUMjg0K C3vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=eJdcn6VolWZ8agRzMDla+/2UdEjq3kJCzEhhmyXUnMk=; b=o7GbFr72u4E8gdBK4/v0UviGIJM78MG9sGg85Nm2q8xo4bIZ/L69/kc3/h027NFvd4 qELOPgWVJVW0mLtQTFfGivvJLIpddgGsyASgvh45GM2tOf9jnrkofZuDq5ZLIj89cesG 54woR75P1TgnP2uLLr8S1Dmim2SmPAA5811rOroQwf8qpilN9kW7Wy1VDb0anRlsAlHj 3NtvdNecQ0dxvRrIfYpbfMzRlWbKxSl8h44eT5p7VY2CjiKNE6WmfFPglxHl3cd3sxCn HWqDh3vGODMz6otZpN5Rp6hStMGJNc/+NKfxcIAvc4TEuSG/dLOvIDgJhgtcZNb3hItq HPfw== X-Gm-Message-State: AOAM532mdZLyIW6jKbIMFwFk83j6W7IcNAhTjq0IyACKutf11ULflj4M +sorsMKGOpcXbdHVOmEJRCfTU0251jA5dR0jwjvkGkTiCoW5lA== X-Google-Smtp-Source: ABdhPJzF22Pgp8Mc69LHjNd0OvqJV37OZ9R0nOaU9sPBikv4SX1P9B34P1H4K5jEf8tir6RMgZSlnp2TTj8++1qH2nA= X-Received: by 2002:a4a:df0a:: with SMTP id i10mr4258491oou.82.1619209901215; Fri, 23 Apr 2021 13:31:41 -0700 (PDT) MIME-Version: 1.0 References: <7FD930F4-37CD-402B-9A06-893818856199@dana.is> <20210411175726.hxnm33mxoska2tsm@chazelas.org> <20210411193154.zkekzvb4o6xmriwo@chazelas.org> <20210413071742.tisslgg5fdqbageg@chazelas.org> <20210422153100.GD154089@zira.vinc17.org> <20210423164525.GA2033191@zira.vinc17.org> In-Reply-To: <20210423164525.GA2033191@zira.vinc17.org> From: Bart Schaefer Date: Fri, 23 Apr 2021 13:31:29 -0700 Message-ID: Subject: Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions) To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 48673 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Fri, Apr 23, 2021 at 9:46 AM Vincent Lefevre wrote: > > On 2021-04-22 11:55:25 -0700, Bart Schaefer wrote: > > On Thu, Apr 22, 2021 at 8:31 AM Vincent Lefevre 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 ))