Library View Topics Framed Contents Revised Topics Previous Topic Next Topic Search Search ResultsPrevious Topic MatchNext Topic Match Notes List Notes Print Download No PDF Handheld DisconnectedHandheld ConnectedHelp

6.1.5.1 Arithmetic Operators



Five binary arithmetic operators and two unary arithmetic operators (Table 15) can be used in arithmetic expressions. They are represented by specific characters that must be preceded and followed by a space.


 Table 15. Binary and Unary Operators                                      
 Binary   
 Operator 
                
 Meaning        
 Unary    
 Operator 
                                    
 Meaning                            
     +      Addition             +      Multiplication by +1               
     -      Subtraction          -      Multiplication by  -1              
     *      Multiplication     
     /      Division           
    **      Exponentiation     


Note: Exponents in fixed-point exponential expressions cannot contain more than 9 digits. The compiler will truncate any exponent with more than 9 digits. In this case, the compiler will issue a diagnostic message if the exponent is a literal or constant; if the exponent is a variable or data-name, a diagnostic is issued at run-time.

Parentheses can be used in arithmetic expressions to specify the order in which elements are to be evaluated.

Expressions within parentheses are evaluated first. When expressions are contained within a nest of parentheses, evaluation proceeds from the least inclusive to the most inclusive set.

When parentheses are not used, or parenthesized expressions are at the same level of inclusiveness, the following hierarchic order is implied:

  1. Unary operator
  2. Exponentiation
  3. Multiplication and division
  4. Addition and subtraction.
    
    
Parentheses either eliminate ambiguities in logic where consecutive operations appear at the same hierarchic level or modify the normal hierarchic sequence of execution when this is necessary. When the order of consecutive operations at the same hierarchic level is not completely specified by parentheses, the order is from left to right.

An arithmetic expression can begin only with a left parenthesis, a unary operator, or an operand (that is, an identifier or a literal). It can end only with a right parenthesis or an operand. An arithmetic expression must contain at least one reference to an identifier or a literal.

There must be a one-to-one correspondence between left and right parentheses in an arithmetic expression, with each left parenthesis placed to the left of its corresponding right parenthesis.

If the first operator in an arithmetic expression is a unary operator, it must be immediately preceded by a left parenthesis if that arithmetic expression immediately follows an identifier or another arithmetic expression.

Table 16shows permissible arithmetic symbol pairs. An arithmetic symbol pair is the combination of two such symbols in sequence. In the table:

Yes
indicates a permissible pairing.
No
indicates that the pairing is not permitted.


 Table 16. Valid Arithmetic Symbol Pairs                                   
                           
                           
                           
                           
        First Symbol       
                 Second Symbol                 
            
 Identifier 
 or Literal 
            
            
 * / ** + - 
 Unary + 
 or      
 Unary - 
     
     
 (   
     
     
 )   
 Identifier or Literal           No           Yes         No      No   Yes 
 *  /   **   +  -                Yes          No         Yes     Yes    No 
 Unary + or Unary -              Yes          No          No     Yes    No 
   (                             Yes          No         Yes     Yes    No 
   )                             No           Yes         No      No   Yes 




Previous Topic Next Topic © Copyright IBM Corp. 1991, 1998

IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.





Return to library:   z/OS | z/OS.e | TPF | z/VSE | z/VM | IBM Hardware | IBM System z Redbooks
Glossary:   IBM terminology
Publications:   How to order publications
Readers:   Download IBM Library Reader | Download IBM Softcopy Reader | Download Adobe® Acrobat® Reader®
Library management:   Download IBM Softcopy Librarian
Contacts:   Contact z/OS


Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.