Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Apr 2003 04:30:51 +0400
From:      Alex Semenyaka <alexs@ratmir.ru>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: /bin/sh and BIG NUMBERS
Message-ID:  <20030408003051.GB18260@snark.ratmir.ru>
In-Reply-To: <20030407024918.GI28391@dan.emsphone.com>
References:  <20030406190054.AA08537B404@hub.freebsd.org> <20030406213453.GB4780@wjv.com> <20030406145748.O1122@atlas.home> <20030407024918.GI28391@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <g>

								SY, Alex



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030408003051.GB18260>