Introduction

Numbers (that is, character strings used as input to REXX arithmetic operations and built-in functions) can be expressed very flexibly. Leading and trailing blanks are permitted, and exponential notation can be used. Some valid numbers are:
    12         /* a whole number                      */
  '-76'        /* a signed whole number               */
    12.76      /* decimal places                      */
' +  0.003 '   /* blanks around the sign and so forth */
    17.        /* same as "17"                        */
      .5       /* same as "0.5"                       */
    4E9        /* exponential notation                */
     0.73e-7   /* exponential notation                */
In exponential notation, a number includes an exponent, a power of ten by which the number is multiplied before use. The exponent indicates how the decimal point is shifted. Thus, in the preceding examples, 4E9 is simply a short way of writing 4000000000, and 0.73e-7 is short for 0.000000073.

The arithmetic operators include addition (+), subtraction (-), multiplication (*), power (**), division (/), prefix plus (+), and prefix minus (-). In addition, there are two further division operators: integer divide (%) divides and returns the integer part; remainder (//) divides and returns the remainder.

The result of an arithmetic operation is formatted as a character string according to definite rules. The most important of these rules are as follows (see the "Definition" section for full details):
  • Results are calculated up to some maximum number of significant digits (the default is 9, but you can alter this with the NUMERIC DIGITS instruction to give whatever accuracy you need). Thus, if a result requires more than 9 digits, it would usually be rounded to 9 digits. For example, the division of 2 by 3 would result in 0.666666667 (it would require an infinite number of digits for perfect accuracy).
  • Except for division and power, trailing zeros are preserved (this is in contrast to most popular calculators, which remove all trailing zeros in the decimal part of results). So, for example:
    2.40 + 2    ->    4.40
    2.40 - 2    ->    0.40
    2.40 * 2    ->    4.80
    2.40 / 2    ->    1.2
    This behavior is desirable for most calculations (especially financial calculations).

    If necessary, you can remove trailing zeros with the STRIP function (see STRIP), or by division by 1.

  • A zero result is always expressed as the single digit 0.
  • Exponential form is used for a result depending on its value and the setting of NUMERIC DIGITS (the default is 9). If the number of places needed before the decimal point exceeds the NUMERIC DIGITS setting, or the number of places after the point exceeds twice the NUMERIC DIGITS setting, the number is expressed in exponential notation:
    1e6 * 1e6    ->    1E+12           /* not 1000000000000 */
    1 / 3E10     ->    3.33333333E-11  /* not 0.0000000000333333333 */

Reference Reference

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/introd.html