|
HP COBOL Reference Manual
7.36 RANGE
Description
The RANGE function returns a value that is equal to the value of the
maximum argument minus the value of the minimum argument.
num
is a numeric or integer argument.
Rules
- The type of this function depends upon the argument types, as
follows:
Arguments |
Function Type |
Integer (all arguments)
|
Integer
|
Numeric (some arguments might be integer)
|
Numeric
|
- The returned value is equal to the greatest value in the series of
arguments minus the least value in the series.
- The comparisons used to determine the greatest and least values are
made according to the rules for simple conditions. (See Chapter 6.)
- If only one argument is specified, the value returned is 0.
Example
COMPUTE RSULT = FUNCTION RANGE (4, 8, 10).
|
The value returned and stored in RSULT (a numeric integer data item) is
6.
7.37 REM
Description
The REM function returns a numeric value that is the remainder of the
first argument divided by the second argument.
arg-1
is a numeric or integer argument.
arg-2
is a numeric or integer argument whose value cannot be 0.
Rules
- The type of this function is numeric.
- The returned value is the remainder of the first argument divided
by the second argument, and is defined as the following expression:
arg-1 -- (arg-2 * FUNCTION INTEGER-PART (arg-1 /
arg-2))
|
(The INTEGER-PART function returns an integer that is the integer
portion of its argument. See Section 7.18. )
Examples
-
COMPUTE RSULT = FUNCTION REM (3, 2).
|
The value returned and stored in RSULT (a numeric data item) is 1.
-
COMPUTE RSULT = FUNCTION REM (4, 2).
|
The value returned and stored in RSULT is 0.
7.38 REVERSE
Description
The REVERSE function returns a character string of exactly the same
length as the argument and whose characters are exactly the same as
those of the argument, except that they are in reverse order.
arg
is an alphabetic or alphanumeric argument at least one character in
length.
Rules
- The type of this function is alphanumeric.
- If the argument is a character string of length n, the returned
value is a character string of length n.
- When 1 is less than or equal to j and j is less than or equal to n,
the character in position j of the returned value is the character from
position (n--j)+1 of the argument.
Example
MOVE FUNCTION REVERSE (STR) TO RSULT.
|
STR and RSULT are alphanumeric data items four characters in length. If
STR contains the value "ABCD" then "DCBA" is the value returned and
stored in RSULT.
If the value "AB" is moved to the four-character data item STR, then
STR will actually contain "AB " with two trailing spaces. Then the
REVERSE function returns the value " BA" with two leading spaces.
7.39 SIN
Description
The SIN function returns a numeric value that approximates the sine of
an angle or arc, expressed in radians, that is specified by the
argument.
angle
is a numeric argument having the value of the measurement in radians of
an angle or arc.
Rules
- The type of this function is numeric.
- The returned value is the approximation of the sine of angle, and
is greater than or equal to -1 and less than or equal to +1.
Example
COMPUTE SIN-RSLT = FUNCTION SIN (X).
|
If the value of X is 3, the approximate sine of an angle of 3 radians
is moved to SIN-RSLT (a numeric data item).
7.40 SQRT
Description
The SQRT function returns a numeric value that approximates the square
root of the argument.
num
is a numeric or integer argument whose value must be 0 or positive.
Rules
- The type of this function is numeric.
- The returned value is the absolute value of the approximation of
the square root of the argument.
Example
COMPUTE RSULT = FUNCTION SQRT (NUM).
|
NUM and RSULT are numeric data items. If NUM has the value 4, the value
returned and stored in RSULT is 2.
7.41 STANDARD-DEVIATION
Description
The STANDARD-DEVIATION function returns a numeric value that
approximates the standard deviation of its arguments.
arg
is a numeric or integer argument.
Rules
- The type of this function is numeric.
- The returned value is the approximation of the standard deviation
of the argument series.
- The returned value is calculated as follows:
- The difference between each argument's value and the arithmetic
mean (average) of the argument series is calculated and squared.
- The values obtained are then added together. This sum is divided by
the number of values in the argument series.
- The square root of the quotient obtained is then calculated. The
returned value is the absolute value of this square root.
- If the argument series consists of only one value, the returned
value is 0.
Example
COMPUTE RSULT = FUNCTION STANDARD-DEVIATION (A, B, C).
|
A, B, C, and RSULT are numeric data items. If A has the value 1, B has
2, and C has 12, the standard deviation of these values (approximately
4.96655) is returned and stored in RSULT.
7.42 SUM
Description
The SUM function returns a value that is the sum of the arguments.
arg
is an integer or numeric argument.
Rules
- The type of this function depends on the argument types, as follows:
Arguments |
Function Type |
Integer (all arguments)
|
Integer
|
Numeric (some arguments might be integer)
|
Numeric
|
- The returned value is the sum of the arguments.
Examples
-
COMPUTE RSULT = FUNCTION SUM (A, B, C).
|
A, B, C, and RSULT are numeric or numeric integer data items. If A has
the value +4, B -2, and C +1, the sum of +3 is the value returned and
stored in RSULT.
-
COMPUTE TOTAL-OUT =
FUNCTION SUM(FUNCTION SQRT(X),
FUNCTION MOD(Y, Z),
A * B,
FUNCTION ACOS(1)).
|
This example shows functions used as arguments to another function. The
data items are all numeric or numeric integer. The value returned and
stored in TOTAL-OUT is the approximate value of the result of adding
the values returned by the functions SQRT, MOD, and ACOS to another
arithmetic expression, A * B.
- The following example shows two arguments that are tables, with
generic (ALL) subscripting, and a third argument that is a literal:
FUNCTION SUM(A(ALL), B(ALL, 2), 4)
|
The number of subscripts shows that A is a one-dimensional table
and B is a two-dimensional table. If A has three occurrences, then
A(ALL) is a set consisting of the elements A(1), A(2), and A(3). If B
has two occurrences in its outer dimension, then B(ALL, 2) is a set
consisting of the elements in B(1, 2) and B(2, 2). If A has three
elements altogether with the values 2 in A(1), 3 in A(2), and 3 in
A(3), and if B has the values 9 in B(1, 2) and 3 in B(2, 2),
then the value returned is 24---the sum of 2, 3, 3 (from table A), 9, 3
(from table B), and 4 (the third argument).
|