NetRexx overview - NetRexx arithmetic

NetRexx Overview, version 2.02 Copyright (c) IBM Corporation, 2001. All rights reserved. © | 22 May 2001
[previous | contents | next]

## NetRexx arithmetic

Character strings in NetRexx are commonly used for arithmetic (assuming, of course, that they represent numbers). The string representation of numbers can include integers, decimal notation, and exponential notation; they are all treated the same way. Here are a few:

      '1234'
      '12.03'
      '-12'
      '120e+7'

The arithmetic operations in NetRexx are designed for people rather than machines, so are decimal rather than binary, do not overflow at certain values, and follow the rules that people use for arithmetic. The operations are completely defined by the ANSI X3.274 standard for Rexx, so correct implementations always give the same results.

An unusual feature of NetRexx arithmetic is the numeric instruction: this may be used to select the arbitrary precision of calculations. You may calculate to whatever precision that you wish (for financial calculations, perhaps), limited only by available memory. For example:

      numeric digits 50
      say 1/7

which would display

      0.14285714285714285714285714285714285714285714285714

The numeric precision can be set for an entire program, or be adjusted at will within the program. The numeric instruction can also be used to select the notation (scientific or engineering) used for numbers in exponential format.

NetRexx also provides simple access to the native binary arithmetic of computers. Using binary arithmetic offers many opportunities for errors, but is useful when performance is paramount. You select binary arithmetic by adding the instruction:

      options binary

at the top of a NetRexx program. The language processor will then use binary arithmetic instead of NetRexx decimal arithmetic for calculations, if it can, throughout the program.

[previous | contents | next]

From The NetRexx Language by Mike Cowlishaw, mfc@uk.ibm.com (ISBN 0-13-806332-X, 197pp, Prentice-Hall, 1997).