Defect Report concerning: IEEE Std. 1003.2-1992, ISO/IEC 9945-2:1993 - Shell & Utilities
Clause: 2.9.2.1
PASC Interpretation Ref: pasc-1003.2-173
Topic: integer constants in aritmetic expressions


This is an unapproved interpretation of PASC 1003.2-1992, ISO/IEC 9945-2:1993 - Shell & Utilities.

Use of the information contained in this unapproved document is at your own risk.

Last update: 20 April,2001


								1003.2-92  #173

 _____________________________________________________________________________


	Interpretation Number:	xxxx
	Topic:   integer constants in aritmetic expressions
	Relevant Sections:  2.9.2.1


PASC Interpretation Request: (Defect Report)
----------------------------  

	Date: Mon, 4 Oct 1999 07:55:34 -0500


PASC Interpretation Request: (Defect Report)
----------------------------  

------------------------------------------------------------------------ 

 7  Defect Report concerning (number and title of International Standard
    or DIS final text, if applicable): 

Shell & Utilities: IEEE Std 1003.2-1992 (ISO 9945-2:1993)

------------------------------------------------------------------------ 

 8  Qualifier (e.g. error, omission, clarification required):

3

Error=1 , Omission=2, Clarification=3

------------------------------------------------------------------------ 

 9  References in document (e.g. page, clause, figure, and/or table
    numbers):

2.9.2.1

------------------------------------------------------------------------ 

10  Nature of defect (complete, concise explanation of the perceived
    problem):


(This was passed to my attention).

I have noticed that most shells don't seem to interpret integer
constants in arithmetic expansions correctly.

As I understand it, arithmetic expressions within $((...)) are required
to be interpreted as per the C Standard (except for certain operators
and floating point).  This means that integer constants should have the
same meaning as in the C Standard, i.e. a leading 0 means octal and a
leading 0x means hex.  However, when I try:

    echo $((010))

most shells output 10 instead of 8, and for:

    echo $((0x10))

most shells report an error, instead of giving 16.

Of the shells that get it right, ksh93 is notable in that the behaviour
appears to have been corrected in version 12/28/93f.  (The 12/28/93e
version gets it wrong, as do all the versions of ksh88 that I tried.)

Is this a correct understanding of the requirements?

------------------------------------------------------------------------ 

11  Solution proposed by the submitter (optional):


None.


------------------------------------------------------------------------ 



Response
___________

        The submitter understands the issue correctly.  According to
        subclause 2.9.2.1 (Arithmetic Precision and Operations), unless
        otherwise specified, integer constants must be handled as signed
        long integers as defined by the ANSI C standard's subclause 3.3.
        (This corresponds to subclause 6.3 in the ISO C 1990 standard.)

        Since subclause 3.6.4 (Arithmetic Expansions) does not specify
        that octal and hexadecimal constants do not have to be
        recognized in $((expression)) constructs, the standard clearly
        requires that octal and hexadecimal constants in the expression
        in an arithmetic expansion must be recognized as specified in
        the C standard.

Rationale
_________

None.


Forwarded to Interpretations group: 4 Oct 1999
Proposal circulated: January 25th 2000
Finalised: 21 March 2000