From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 7 17:31:00 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A138D37B431 for ; Mon, 7 Apr 2003 17:31:00 -0700 (PDT) Received: from snark.ratmir.ru (snark.ratmir.ru [213.24.248.177]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0017643F75 for ; Mon, 7 Apr 2003 17:30:58 -0700 (PDT) (envelope-from freebsd@snark.ratmir.ru) Received: from snark.ratmir.ru (freebsd@localhost [127.0.0.1]) by snark.ratmir.ru (8.12.9/8.12.9) with ESMTP id h380UqDR018342; Tue, 8 Apr 2003 04:30:52 +0400 (MSD) (envelope-from freebsd@snark.ratmir.ru) Received: (from freebsd@localhost) by snark.ratmir.ru (8.12.9/8.12.9/Submit) id h380Up8O018337; Tue, 8 Apr 2003 04:30:51 +0400 (MSD) Date: Tue, 8 Apr 2003 04:30:51 +0400 From: Alex Semenyaka To: Dan Nelson Message-ID: <20030408003051.GB18260@snark.ratmir.ru> References: <20030406190054.AA08537B404@hub.freebsd.org> <20030406213453.GB4780@wjv.com> <20030406145748.O1122@atlas.home> <20030407024918.GI28391@dan.emsphone.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030407024918.GI28391@dan.emsphone.com> User-Agent: Mutt/1.5.4i cc: freebsd-hackers@freebsd.org Subject: Re: /bin/sh and BIG NUMBERS X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Apr 2003 00:31:01 -0000 On Sun, Apr 06, 2003 at 09:49:19PM -0500, Dan Nelson wrote: > POSIX requirements for math in shells are pretty lenient: > > * Only signed long integer arithmetic is required. > > As an extension, the shell may recognize arithmetic expressions > beyond those listed. The shell may use a signed integer type with a > rank larger than the rank of signed long. The shell may use a > real-floating type instead of signed long as long as it does not > affect the results in cases where there is no overflow. Similar situation with Single UNIX Specification v.3. There is explicit permission to work with number longer that of type ``long'': Next, the shell shall treat this as an arithmetic expression and substitute the value of the expression. The arithmetic expression shall be processed according to the rules given in Arithmetic Precision and Operations , with the following exceptions: * Only signed long integer arithmetic is required. * Only the decimal-constant, octal-constant, and hexadecimal-constant constants specified in the ISO C standard, Section 6.4.4.1 are required to be recognized as constants. * The sizeof() operator and the prefix and postfix "++" and "--" operators are not required. * Selection, iteration, and jump statements are not supported. As an extension, the shell may recognize arithmetic expressions beyond those listed. The shell may use a signed integer type with a rank larger than the rank of signed long. V.2 is less specific, but there is also no prohibition to extend shell's integer type beyond the long type ranges: Next, the shell will treat this as an arithmetic expression and substitute the value of the expression. The arithmetic expression will be processed according to the rules of the ISO C standard, with the following exceptions: * Only integer arithmetic is required. * The sizeof() operator and the prefix and postfix ++ and -- operators are not required. * Selection, iteration and jump statements are not supported. As an extension, the shell may recognise arithmetic expressions beyond those listed. If the expression is invalid, the expansion will fail and the shell will write a message to standard error indicating the failure. So I did not try to introduce something illegal as far as I understand SY, Alex