/bin/sh and BIG NUMBERS

Alex Semenyaka alexs at ratmir.ru
Mon Apr 7 17:31:01 PDT 2003


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


More information about the freebsd-hackers mailing list