ABS | Returns the absolute value of a number. |
BIT | Performs various bit manipulations, bit tests, and shifts. |
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. |
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
Performs various bit manipulations, bit tests, and shifts. Unlike operations such as BITAND, BITOR, etc, the values are not treated like character strings, but rather, numeric strings.
Synopsis
value = BIT(Value, AdditionalArg, Operation)
Args
Value is a numeric value. It cannot have a fractional part.
Operation is one of the following:
Option Meaning TEST Test a specific bit (ie, return '0' if it's clear, or '1' if it's set). CLR Clear a specific bit (ie, change it to a '0'). SET Set a specific bit (ie, change it to a '1'). FLIP Toggle a specific bit (ie, if it was '0', change it to a '1', and vice versa). AND Mathematically AND Value with the AdditionalArg. OR Mathematically OR Value with the AdditionalArg. XOR Mathematically Exclusive OR Value with the AdditionalArg. SHR hift all bits to the right. (Toss away bits that get "shifted out" on the right, and replace them with 0 bits on the left). SHL Shift all bits to the left. (Toss away bits that get "shifted out" on the left, and replace them with 0 bits on the right). ROR Rotate all bits to the right. ROL Rotate all bits to the left. XTRT Extract a bit field.
If omitted, Operation defaults to 'TEST'.
Additional is utilized differently depending upon Operation.
For ROR, ROL, SHR, and SHL, Additional is the number of bits to shift/rotate, followed by the precision of the value (ie, 32 for 32-bits), each separated by a space. If Additional is omitted, it defaults to "1 32".
For AND, OR, or XOR, Additional is the other numeric value to AND/OR/XOR with, and is expressed in hexadecimal notation, for example 'F0'. (Use D2X if your Additional arg is in decimal numeric format). If omitted, defaults to 'FFFF' (ie, affects the low word).
For TEST, SET, CLR, or FLIP, Additional is the bit number, where 0 is the first (leftmost bit). If omitted, it defaults to 0.
For XTRT, Additional is the bit number to start at, followed by the bit number to stop at, each separated by a space. If omitted it defaults to "16 31" (ie, the high word of a 32-bit value).
Returns
The result depends upon which Operation is performed.
The new value is returned for operations AND, OR, XOR, ROR, ROL, SHR, SHL, SET, CLR, or FLIP. It is expressed as a standard REXX numeric string (ie, base 10).
For TEST, a '0' is returned if the bit is clear, or a '1' is returned if the bit is set.
For XTRT, the new value is returned with the bits shifted down to the right, and expressed as a standard numeric string.
Notes
The original numbers are not altered.
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
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
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
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
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
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 can't 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
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
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
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
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
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