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 26984 invoked from network); 24 Apr 2021 23:02:41 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Apr 2021 23:02:41 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1619305361; b=injJ5MDIUmPGyY0HwGHgoEUAL8eKtu7j6/j7X+Lnk2x0O1xE3diduA9eVb2CSWs2S7opicl31r j+ugC6cC0ksXqpIETVBc/rUzu8SQHYBtjkWXcAgjKQka4Xbh7be0AsUnh5e9I1pX/9RMREGhLV zOGU06L/9Z2nvAxb0CvzO2RWuEiFxE66rt85VNLLf34D6gEWQ+8QfdxYWgBU0eFd8YnLgeLjqn RHkpbGZmAVOWZxG5dmxhYr4a5AnEVcGD40kgZSOPcuNmDiycPSFiT0DWCYMsx2q9V/953g50YF tNamywy9xguCMXROMkypggRNO4sCFTEviEEePf3955nXFg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1619305361; bh=cPZWFTjFAr8NcV+7U9Zu/1X6RCbfGTg9VC34Egmeg4Q=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=MsELLntfom3C1x17LaQPQDyn4qFqyKNYy4qkUXIs1EGNJC4NIFNHWgh4Llo3Sqb7TN6jUuQbBA 8xX66mXEi7cynxqLeDEji5ipDtRBFXssiysfG8tAYs9Y3n3WKDmwhRdpicAfW+o+TT82QrRLw5 LRi7Qrv//gq49wC6yUtlesEQxvGwi6TJkxVJ5yzWl/Z2pRZSzoggjI4r7P+Af/tNUoeMaGNUbG KJKI/XsnXZcZERyooKgR0zA1FjImBHE0RxYRL+Y4x5Coi+NoOzvrHirfYQpXexpOf6/HM8lDio nhEbClm1EpG2my1y85YDFH2NQWf6VQIwQvweBX1AiNsUSQ==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=I9Uh+m4ByUAKhm/dD9mK2CZs6bKmBWZTNoGrPxVcOF8=; b=WPiWEk9WmI2s/dy6nA7osd5W41 t/Pl4T20Lyaugb8rjfpPV7u3VQo2aaJxk+EEg3Z1KLI0jKLzwREsMcshSPmIGbatMi6iXyZzN6X2z WTlnDVmBnd1uNPq/viVhSaY6Slcnhhi+brqgAwvZwDtkil1ccsW497qm0vv9wEIU9rBbbP9AhiJRP QQeGz7xKT/jG7JQjxnmfpUqKC+L4AvIWgNaMV02nNZf+jlXUJYe/K+nqKYUEbsdcn846qEOg+AZw1 PEJ8W9T+QyBLoqilHzi25AbguOUIjr7OF6xL1kCK5ibmv2DZpOGq8S9QiktrXpIr/fh5XBrqHQS/I FDbpfXLg==; Received: from authenticated user by zero.zsh.org with local id 1laRIO-000B5s-LN; Sat, 24 Apr 2021 23:02:40 +0000 Authentication-Results: zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none Received: from joooj.vinc17.net ([155.133.131.76]:53734) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1laRI6-000Aov-Az; Sat, 24 Apr 2021 23:02:23 +0000 Received: from smtp-zira.vinc17.net (lfbn-tou-1-1431-42.w90-89.abo.wanadoo.fr [90.89.233.42]) by joooj.vinc17.net (Postfix) with ESMTPSA id BF89E10B; Sun, 25 Apr 2021 01:02:21 +0200 (CEST) Received: by zira.vinc17.org (Postfix, from userid 1000) id BB5F3C2072E; Sun, 25 Apr 2021 01:02:19 +0200 (CEST) Date: Sun, 25 Apr 2021 01:02:19 +0200 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: sh emulation POSIX non-conformances ("inf"/"Inf" in arithmetic expressions) Message-ID: <20210424230219.GD2587578@zira.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org References: <20210411175726.hxnm33mxoska2tsm@chazelas.org> <20210411193154.zkekzvb4o6xmriwo@chazelas.org> <20210413071742.tisslgg5fdqbageg@chazelas.org> <20210422153100.GD154089@zira.vinc17.org> <20210423164525.GA2033191@zira.vinc17.org> <55222-1619218004.791735@3FXq.NU49.vlrg> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55222-1619218004.791735@3FXq.NU49.vlrg> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.0.6+160 (30e657d3) vl-137001 (2021-04-24) X-Seq: 48697 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 2021-04-24 00:46:44 +0200, Oliver Kiddle wrote: > Bart Schaefer wrote: > > On Fri, Apr 23, 2021 at 9:46 AM Vincent Lefevre wrote: > > > > > IMHO, zsh should also output a warning when such variables are used. > > I disagree. We also have variables named 0, 1, 2, 3 and so on - the > positional parameters. But nobody would suggest warning about literal > value 7 in maths context. This is different: the digits are already used in integers, and the behavior is the same in all shells. > > So, it's the "expend effort on a check that is nearly always going to > > fail" option. > > I can just about see the case for warning on typeset -i/-F inf or nan > but not on use. The traditional Unix approach is not to stop people who > choose to shoot themselves in the foot. In a maths expression, you're > going to end up with inf, -inf or nan as your result anyway so it > quickly becomes fairly obvious what is going on. People could waste a lot of time finding what is going on, in particular those who don't use floating point at all. > If we're worrying about POSIX compliance, it'd be easy enough to disable > Inf and NaN in POSIX mode but there are dozens of special variables > defined that aren't in the POSIX spec either and which could clash. However, it is a bit easier to see what is going on with special variables. And they have been documented for a long time. On the opposite, the zsh manual (for 5.8) is silent on Inf and NaN. And both for the behavior and documentation, be careful with the locales, in particular in Turkish ones. I don't know whether this is expected in zsh, but... zira% zsh -fc 'export LC_ALL=fr_FR.utf8; echo $((Inf)) $((inf))' Inf Inf zira% zsh -fc 'export LC_ALL=tr_TR.utf8; echo $((Inf)) $((inf))' Inf 0 With ksh93: zira% ksh93 -fc 'export LC_ALL=fr_FR.utf8; echo $((Inf)) $((inf))' inf inf zira% ksh93 -fc 'export LC_ALL=tr_TR.utf8; echo $((Inf)) $((inf))' inf inf > It is generally helpful to be able to re-input the output as input > in a later line of code. Even with the POSIX behavior, a problem is unlikely to occur, because zsh uses a mix of uppercase and lowercase letters, and this is uncommon in variable names. Moreover, if people get Inf or NaN in their computation, I doubt that they would use such variable names. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)