Using REXX Math Commands

ID: Q99064


The information in this article applies to:
  • Microsoft LAN Manager, versions 2.1, 2.1a, 2.2


SUMMARY

This article lists the math function capabilities of the REXX programming language and gives examples.


MORE INFORMATION

DISCLAIMER: This article is for readers knowledgeable enough to use its information in developing programs. Rather than describe the REXX programming language extensively, it offers a quick reference for someone writing simple routines. PSS cannot s pport programming efforts beyond reproducing and submitting problems with the language implementation itself. If you need more or different information, consult one of the REXX references such as "The REXX Language, A Practical Approach to Programming" by M. F. Cowlishaw, Prentice-Hall, Englewood Cliffs, 1985.

Examples are given at the bottom of the listing. Braces ({}) are used to indicate comments.


DIGITS() { returns current setting of number of digits }

FORM() { returns the current format of numbers (Ex:
SCIENTIFIC) } 
FORMAT(number, integer, fraction, exp_digits, exp_trigger) { returns the supplied number formatted with up to 'integer' characters (actual digits or spaces) to the left of the decimal ('integer' characters must be able to hold the integral part of the number or an error occurs), 'fraction' digits to the right of the decimal (rounding any excess), exp_digits appearing after the 'E' if exponential form is used and exp_trigger specifying how many digits can appear before the decimal before switching to exponential notation (using exp_trigger can prevent a number whose integral part is longer than 'integer' from causing an error by triggering exponential notation, for such numbers this is only true if exp_trigger is not greater than 'integer'. }
FUZZ() { returns current setting of numeric fuzz }

MAX(i, j, k, l, m, n ...) { returns the maximum value in the given list. }

MIN(i, j, k, l, m, n ...) { returns the minimum value in the given list. }

NUMERIC DIGITS expression { sets the number of numeric digits to the value of expression. }

NUMERIC FORM [SCIENTIFIC|ENGINEERING] { sets the form numbers are to be expressed in. }

NUMERIC FUZZ expression { sets the value of numeric fuzz (the number of digits the DIGITS value is reduced by during computations/comparisons) to the value of expression. }

RANDOM(minimum_value, maximum_value, seed_value) { returns a quasi-random number within the minimum and maximum values given and will use an optional seed_value if specified. }

SIGN(number) { returns the sign of a number as -1 for negative, 1 for positive or zero. }

TRUNC(number, maximum_digits) { returns a number truncated to maximum_digits following the decimal point. }
Examples follow. Create a REXX program and run it to see the results.

say 'max(1,2,5,7,4,3,7,9) returns ' max(1,2,5,7,4,3,7,9)
say 'min(1,2,5,7,4,3,7,9) returns ' min(1,2,5,7,4,3,7,9)
say 'sign(-27) returns ' sign(-27)
say 'sign(43) returns ' sign(43)
say 'sign(0) returns ' sign(0)
say 'trunc(12345.67890,3) returns ' trunc(12345.67890,3)
say 'trunc(12345.67890,0) returns ' trunc(12345.67890,0)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'random(1,5) returns ' random(1,5)
say 'changing seed value'
say 'random(1,5,4) returns ' random(1,5,4)
say 'random(1,5,37) returns ' random(1,5,37)
say 'Changing range'
say 'random(5,8) returns ' random(5,8)
say  'Digits set to ' digits()
say '1.2345 * 9.87654 is ' 1.2345 * 9.87654
numeric digits 3
say 'Numeric digits now = 3'
say '1.2345 * 9.87654 is ' 1.2345 * 9.87654
numeric digits 9
say 'Numeric digits back to 9'
say 'Form = ' form()
say '246e8 * 135e7 = ' 246e8 * 135e7
numeric form engineering
say 'Numeric form is now engineering'
say '246e8 * 135e7 = ' 246e8 * 135e7
say 'Numeric fuzz = ' fuzz()
say '4.4444 < 4.44444 returns ' 4.4444 < 4.44444
numeric fuzz 8
say 'Numeric fuzz now = ' fuzz()
say '4.4444 < 4.44444 returns ' 4.4444 < 4.44444
say 'format(123.456789,4,3) is ' format(123.456789,4,3)
say 'format(123456,6,2,2,3) is ' format(123456,6,2,2,3)
say 'format(123456,4,2,2,4) is ' format(123456,4,2,2,4)
say 'format(123456,3,2,2,3) is ' format(123456,3,2,2,3)
say 'format(123456,4,2,3,3) is ' format(123456,4,2,3,3)
say 'format(12345.6,6,2,2,3) is ' format(12345.6,6,2,2,3)
say 'format(1234.56,6,2,2,3) is ' format(1234.56,6,2,2,3)
say 'format(123.456,6,2,2,3) is ' format(123.456,6,2,2,3)
say 'format(12.3456,6,2,2,3) is ' format(12.3456,6,2,2,3)
say 'format(1.23456,6,2,2,3) is ' format(1.23456,6,2,2,3)
say Error conditions follow, progressively remark them out!
say format(123.456789,2,3)
say format(123456,0,2,2,3) 

Additional query words: 2.1 2.1a 2.20 REXX

Keywords :
Version : :2.1,2.1a,2.2
Platform :
Issue type :


Last Reviewed: November 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.