The following built-in functions operate upon numeric values (numeric strings and numeric constants) to perform mathematical operations.

ABS Returns the absolute value of a number.
BITAND Logically ANDs two numbers.
BITOR Logically ORs two numbers.
BITXOR Logically XORs two numbers.
DIGITS Returns the current setting of the NUMERIC DIGITS instruction.
FORM Returns the current setting of the NUMERIC FORM instruction.
FORMAT Rounds and formats a number.
FUZZ Returns the current setting of the NUMERIC FUZZ instruction.
MAX Returns the largest number from a given list of numbers.
MIN Returns the smallest number from a given list of numbers.
SIGN Tests whether a number is <, =, or > 0 after rounding.
TRUNC Truncates a number to a specified number of digits.


ABS

Returns the absolute value of a numeric value.

Synopsis
absoluteval = ABS(number)

Args

number is the original number.

Returns

The absolute value of the original number.

Notes

The returned absolute value has no sign, and is normalized according to the current NUMERIC DIGITS/FUZZ settings. So, the return value may not be strictly equal to the absolute value of the original number.

The original number is not altered.

Examples

Example use
Return value
ABS(-42)
42
ABS('123.45')
123.45
ABS('-1.0E1')
10

See also

SIGN


BITAND

Logically ANDs two numeric values, bit by bit.

Synopsis
and_value = BITAND(number1, number2, padchar)

Args

number1 and number2 are the two original numbers to AND together. If number2 is omitted, then it defaults to an empty string.

If one numeric value is shorter (ie, has less digits) than the other, and padchar is specified, then the shorter one is padded out on the right-hand side with padchar characters until both values are equal length. If padchar is omitted, then the extraneous digits (on the right) of the longer value are simply appended to the shorter value.

Returns

The result of AND'ing the two numeric values.

Notes

The original numbers are not altered.

Examples

Example use
Return value
BITAND('123456'x, '3456'x)
'101456'x
BITAND('123456'x, '3456'x, 'f0'x)
'101450'x
BITAND('53'x,'6F'x)
'43'x
BITAND('1A'x,'5C5C'x,'0F'X)
'180C'x

See also

TRANSLATE, BITOR, BITXOR


BITOR

Logically ORs two numeric values, bit by bit.

Synopsis
or_value = BITOR(number1, number2, padchar)

Args

number1 and number2 are the two original numbers to OR together. If number2 is omitted, then it defaults to an empty string.

If one numeric value is shorter (ie, has less digits) than the other, and padchar is specified, then the shorter one is padded out on the right-hand side with padchar characters until both values are equal length. If padchar is omitted, then the extraneous digits (on the right) of the longer value are simply appended to the shorter value.

Returns

The result of OR'ing the two numeric values.

Notes

The original numbers are not altered.

Examples

Example use
Return value
BITOR('123456'x, '3456'x)
'367656'x
BITOR('123456'x, '3456'x, 'f0'x)
'3676F6'x
BITOR('6C'x,'31'x)
'7D'x
BITOR('6C'x,'5A5A'x,'FO'x)
'7EFA'x

See also

TRANSLATE, BITAND, BITXOR


BITXOR

Logically XORs two numeric values, bit by bit.

Synopsis
xor_value = BITXOR(number1, number2, padchar)

Args

number1 and number2 are the two original numbers to XOR together. If number2 is omitted, then it defaults to an empty string.

If one numeric value is shorter (ie, has less digits) than the other, and padchar is specified, then the shorter one is padded out on the right-hand side with padchar characters until both values are equal length. If padchar is omitted, then the extraneous digits (on the right) of the longer value are simply appended to the shorter value.

Returns

The result of XOR'ing the two numeric values.

Notes

The original numbers are not altered.

Examples

Example use
Return value
BITXOR('123456'x, '3456'x)
'266256'x
BITXOR('123456'x, '3456'x, 'f0'x)
'2662A6'x
BITXOR('12'x,'22'x)
'30'x
BITXOR('1211'x,'222222'x,'20'x)
'303302'x

See also

TRANSLATE, BITAND, BITOR


DIGITS

Returns the current setting of the NUMERIC DIGITS instruction.

Synopsis
setting = DIGITS()

Args

None.

Returns

The current setting of NUMERIC DIGITS. (ie, Either the default setting when the interpreter was started, or the last setting you made via the NUMERIC DIGITS instruction).

Notes

The NUMERIC DIGITS setting determines the number of significant digits that REXX puts in the results of mathematical operations such as addition, subtraction, multiplication, or division. Result strings are rounded to this precision.

The default setting for most interpreters is 9 digits. Reginald allows setting the default via the REXX Administration Tool.

See also

FORM, FUZZ


FORM

Returns the current setting of the NUMERIC FORM instruction.

Synopsis
setting = FORM()

Args

None.

Returns

The current setting of NUMERIC FORM. (ie, Either the default setting when the interpreter was started, or the last setting you made via the NUMERIC FORM instruction).

Notes

The NUMERIC FORM setting determines the form in which exponential numbers are written. It can be set to either 'ENGINEERING' or 'SCIENTIFIC'. The former uses a mantissa in the range 1.000... to 9.999..., and an exponent which can be any integer; while the latter uses a mantissa in the range 1.000... to 999.999..., and an exponent which is dividable by 3.

NUMERIC FORM never affects REXX's decision when to use exponential form versus normal floating point form in a mathematical result -- it affects only the appearance of the exponential form once REXX has decided to use exponential form to create a mathematical result string.

See also

DIGITS, FUZZ


FORMAT

Rounds a number. Can also format a number to fit within a specified number of characters.

Synopsis
formatted = FORMAT(number, before, after, expp, expt)

Args

number is the original number. before and after determine how many digits are formatted before and after the decimal point, respectively.

before determines the character width in which the integer part of number is fit. For example, if before is 4, then the integer part of the number will be fit into 4 character, padding out with spaces on the left-hand side to fit within 4 characters if necessary. A place for any negative (ie, minus) sign should be considered in the width, if applicable. If before is not large enough to hold all the digits of the integer part (including a negative sign if relevant), a SYNTAX error is reported. Therefore, before can never be less than 1 for a positive number, and never less than 2 for a negative number. Any leading zeros will be trimmed off the integer part, except a single zero digit if the integer part of number is empty. If before is omitted, the default is to use as many characters as are needed to fit the integer part.

after determines the character width in which the fractional part of number is fit. For example, if after is 4, then the fractional part of the number will be fit into 4 characters, padding out with zeros on the right-hand side to fit within 4 characters, or rounding off (ie, not truncating) the fractional part to fit within 4 characters, if necessary. The decimal point itself is not considered a part of the width. The decimal point will be omitted if there is no fractional part in number. If after is 0, then number is rounded to the nearest integer. If after is omitted, the default is to use as many characters as are needed to fit the fractional part.

expp determines the character width in which the exponent is fit. This is the size of only the digits of the exponent, not including the 'E' and any negative sign. (ie, The final width of the exponent will be two characters more than expp). If expp is 0, then exponential form will not be used. If expp is omitted, the default is to use as many characters as are needed to fit the exponent. expp cannot be negative, nor have a fractional component -- it must be a positive, whole number. If expp is not 0, but also not large enough to hold the exponent, this raises a SYNTAX error. expt is the number of digits, above which, number will be formatted in exponential form (instead of simple form). Normally, the default precision (NUMERIC DIGITS setting) is used, but if expt is specified, it will override that. If expt is 0, exponential form will always be used. Exponential form is used if more digits than expt is needed in the integer part, or more than twice expt digits are needed in the fractional part. expt cannot be negative, nor have a fractional component -- it must be a positive, whole number.

Returns

The formatted number.

Notes

If expp is 0, then expt is ignored.

after will mean different things in exponential and simple form. If after is 3, then in simple form it will force the precision to 0.001, no matter the magnitude of the number. If in exponential form, it will force the number to 4 digits precision.

If NUMERIC FORM ENGINEERING is in effect, up to 3 digits might be needed for the integer part of the result (ie, before may need to be at least 3).

The original number is not altered. Only the returned number from FORMAT is formatted.

Examples

Example use
Return value
FORMAT(12.34, 3, 4)
' 12.3400'
FORMAT(12.34, 3, , 3, 0)
'  1.234E+001'
FORMAT(12.34, 3, 1)
' 12.3'
FORMAT(12.34, 3, 0)
' 12'
FORMAT(12.34, , , , 0)
'1.234E+1'
FORMAT(12.34, , , 0)
'12.34'
FORMAT(12.34, , ,0, 0)
'12.34'

See also

TRUNC, SPACE, CENTER


FUZZ

Returns the current setting of the NUMERIC FUZZ instruction.

Synopsis
setting = FUZZ()

Args

None.

Returns

The current setting of NUMERIC FUZZ. (ie, Either the default setting when the interpreter was started, or the last setting you made via the NUMERIC FUZZ instruction).

Notes

The NUMERIC FUZZ setting is used in comparisons of two values that happen to be numeric. Normally, two numbers must have identical numeric values for all of their most significant digits in order to be considered equal. How many digits are considered is determined by the NUMERIC DIGITS setting. If DIGITS is 4, then 12345 and 12346 are equal, but not 12345 and 12356. However, when FUZZ is non-zero, then only the DIGITS minus FUZZ most significant digits are checked. For example, if DIGITS is 4 and FUZZ is 2, then 1234 and 1245 are equal, but not 1234 and 1345.

See also

FORM, DIGITS


MAX

Returns the largest number from a given list of numbers.

Synopsis
largest = MAX(first, second, third, ...)

Args

first, second, third, etc, are the list of numbers. You can list as many numbers as you like, each separated by a comma. (Each number to be considered is a separate arg).

Returns

A largest number out of the list of supplied numbers.

Notes

The returned value is the largest number normalized according to NUMERIC DIGITS/FUZZ settings. So, the return value may not be strictly equal to the largest number supplied.

Examples

Example use
Return value
MAX(1, 2, 3, 5, 4)
5
MAX(6)
6
MAX(-2, 0, 2)
2
MAX(-4, .001E3, 4)
4

See also

MIN


MIN

Returns the smallest number from a given list of numbers.

Synopsis
smallest = MIN(first, second, third, ...)

Args

first, second, third, etc, are the list of numbers. You can list as many numbers as you like, each separated by a comma. (Each number to be considered is a separate arg).

Returns

A smallest number out of the list of supplied numbers.

Notes

The returned value is the smallest number normalized according to NUMERIC DIGITS/FUZZ settings. So, the return value may not be strictly equal to the smallest number supplied.

Examples

Example use
Return value
MIN(1, 2, 3, 5, 4)
1
MIN(6)
6
MIN(-2, 0, 2)
-2
MIN(-4, .001E3, 4)
-4

See also

MAX


SIGN

Tests whether a number is <, =, or > 0 after rounding.

Synopsis
result = SIGN(number)

number is the original number.

Returns

If the number is then less than 0, SIGN returns -1. If it is 0, SIGN returns 0. If it is greater than 0, SIGN returns 1.

Notes

The number is normalized according to the current NUMERIC DIGITS/FUZZ settings before its sign is tested. So, the value could be rounded to 0, which would produce a sign that is different than the original number's sign.

The original number is not altered.

Examples

Example use
Return value
SIGN(-12)
-1
SIGN(42)
1
SIGN(-0.00000012)
-1
SIGN(0.000)
0
SIGN(-0.0)
0

See also

ABS


TRUNC

Truncates a number to a specified number of digits.

Synopsis
truncated = TRUNC(number, digits)

Args

number is the original number.

digits is the desired number of digits. If omitted, it defaults to 0. (ie, the fractional portion of the number is discarded, and only the integer portion is returned). If digits is larger than the number of decimal places in the original number, then number is padded out with extra zeros on the left.

Returns

The number, truncated to the specified number of digits.

Notes

The returned number is always in simple form -- never exponential form -- regardless of the current NUMERIC FORM setting.

The original number is not altered.

To round a number, use FORMAT instead.

Examples

Example use
Return value
TRUNC(12.34)
12
TRUNC(12.99)
12 /* Truncated, not rounded */
TRUNC(12.34, 4)
12.3400
TRUNC(12.3456, 2)
12.34

See also

FORMAT