LET [ HP Transact Documentation Update Notice ] MPE/iX 5.5 Documentation
HP Transact Documentation Update Notice
LET
Specifies arithmetic operations.
Syntax
LET destination-variable = arithmetic-expression
[,ERROR=label[([item-name])]];
The LET verb is primarily used to perform arithmetic operations.
NOTE At one time the LET verb was also used to manipulate arrays through
an optional syntax variation that used the LET OFFSET option.
However, the current version of Transact supports subscripting of
arrays so that use of the LET OFFSET is no longer necessary.
Although it is now recommended that you use subscripts to
manipulate arrays, the LET OFFSET option is still available and is
described later to aid in maintaining older Transact programs.
LET, unlike MOVE, checks that the data types of items being assigned are
compatible with the item to which they are assigned. If necessary, LET
performs type conversion.
Statement Parts
destination- An item name that identifies a location in the data
variable register, or Transact-defined name of a special purpose
register. The result of the operation is placed in this
variable. The destination variable may be any of the names
listed below. All of the names except item-name are stored
in a special area outside the list and data registers.
They are, therefore, not affected by SET(STACK) or
RESET(STACK).
(item-name The computed or assigned value of item-name.
[(sub- The item-name identifies a location in the
script)]) data register. The item-name can be
subscripted if an array item is referenced.
(See "Array Subscripting" in Chapter 3.)
LINE An integer, defined as I(5,,2) in Transact/V
or defined as I(10,,4) in Transact/iX, that
contains the computed or assigned value of
the line counter for the current line of
terminal display or line printer output.
OFFSET An integer, defined as I(5,,2) in Transact/V
(item-name) or defined as I(10,,4) in Transact/iX, that
contains the offset of an item starting at
position zero.
PAGE An integer, defined as I(5,,2) in Transact/V
or defined as I(10,,4) in Transact/iX, that
contains the computed or assigned value of
the page counter.
PLINE An integer, defined as I(5,,2) in Transact/V
or defined as I(10,,4) in Transact/iX, that
contains the computed or assigned value of
the line counter for the current line of line
printer output.
STATUS An integer, defined as I(5,,2) in Transact/V
or defined as I(10,,4) in Transact/iX, that
contains the computed or assigned value of
the status register.
TLINE An integer, defined as I(5,,2) in Transact/V
or defined as I(10,,4) in Transact/iX, that
contains the computed or assigned value of
the line counter for the current line of
terminal display output.
arithmetic- A single source, or multiple sources connected by
expression arithmetic operators in the format:
[-]source1 [operator source2]...[operator sourcen]
[-] If the expression is preceded by a minus
sign, its negative is assigned.
____________________________________________
NOTE If a positive-only integer is set to a
negative number, an error occurs. The
value of the specified item will be
undefined. Since the outcome is
undefined, you should not rely on this
procedure to zero out values. Instead,
use the ERROR= option to branch to a
label and negate the desired fields.
____________________________________________
source An item-name[(subscript)] within
parentheses, a numeric constant, one of the
Transact-defined names listed above under the
description of destination-variable, or one
of the functions listed below and described
later in this verb.
The item-name can be subscripted if an array
item is being referenced. (See "Array
Subscripting" in Chapter 3.)
function ASCII
LENGTH
LN
LOG
POSITION
SQRT
VALUE
operator + addition
- subtraction
* multiplication
/ division giving the quotient
// division giving the remainder
** exponentiation
ERROR=label An option to cause branching on arithmetic errors. In
[([item- addition to branching and resetting the list register, this
name])] option causes the status register to be set to a value that
identifies the type of error. (See "Error Branching" later
in the description of this verb.)
label The label to which the program is to branch when
an arithmetic error is encountered.
item-name The point to which the list register is to be
reset before branching to the error label. If
you do not specify an item-name (for example,
ERROR=label() or ERROR=label), the list register
is reset to empty. If you specify an asterisk
(for example, ERROR=label(*)), the list register
is not changed.
The order of precedence for arithmetic operators is:
** exponentiation
// division giving remainder
/ division giving quotient
* multiplication
- subtraction
+ addition
You can change the order of evaluation by using square brackets. For
example, the following two statements may yield different results:
LET (A)=(B) + (C)/(D);
LET (A)=[(B) + (C)]/(D);
[REV BEG]
Invalid Values Cause Differing Results
If a problem occurs within a LET statement, the results obtained with
Transact/V and Transact/iX may differ. Transact/V will try to substitute
a zero for the invalid value and continue with the assignment.
Transact/iX will leave the existing value intact and not re-assign the
target. This occurs under the following situations:
* Unsubscripted source array is shorter than unsubscripted target
array.
* Item is invalid.
* Subscript for a source array is invalid.
* Argument for a function is invalid.
To avoid the arithmetic differences, use the same number of elements for
unsubscripted arrays, and do not use X or U data types in an arithmetic
expression.[REV END]
Functions
The following sections describe the functions available within the LET
verb, including parameters and examples. These functions can be used
whenever an expression can be used. An additional set of parentheses
around item parameters is optional. For example, SQRT(Z) and SQRT((Z))
are both acceptable.
A function cannot be embedded or nested in another function. In the
following example, the compiler will treat LOG as an array item and
generate a warning if LOG is not defined.
LET (A) = SQRT(LOG(100.0));
The ERROR= option causes the branch to a label to be taken when specific
errors occur while processing a function just as specific errors in a LET
statement without a function cause such a branch to be taken.
ASCII
The ASCII function converts the first character of a string to the number
for its ASCII code. The result will be a number between 0 and 255
inclusive. This function is only valid for string constants and data
items of type X or U.
Syntax
ASCII({(item-name[(subscript)])})
{"character-string" }
Examples
LET (CODE) = ASCII("A");
Before After
CODE I(5) 0 65
LET (CODE) = ASCII((ARRAY(2)));
Before After
ARRAY(2) X(4) BCDE BCDE
CODE I(5) 123 66
LENGTH
The LENGTH function returns the length in characters of a string by
returning the integer index of the position of the last non-blank
character in the string. Embedded blanks are included in this count, but
trailing blanks are not included. Nulls are considered valid characters
and are counted.
When calculating the length of an X or U item, the maximum length will be
the display length. This function is only valid for string constants and
data items of type X or U.
Syntax
LENGTH({(item-name[(subscript)])})
{"character-string" }
Examples
LET (COUNT) = LENGTH("__APPLE_");
Before After
COUNT I(5) 0 7
LET (COUNT) = LENGTH((ARRAY(2)));
Before After
ARRAY(2) X(7) ABC_DE_ ABC_DE_
COUNT I(5) 0 6
LET (COUNT) = LENGTH("____");
Before After
COUNT I(5) 0 0
LN
The LN function computes the natural logarithm of a number.
NOTE Previously, an additional set of parentheses was not allowed around
an item parameter in this function. This has been changed so that
additional parentheses around an item are optional. For example,
LN(A) and LN((A)) are both acceptable.
Syntax
LN({(item-name[(subscript)])})
{numeric-constant }
Examples
LET (RESULT) = LN(100.0);
Before After
RESULT R(6,2,4) 0.00 4.61
LET (RESULT) = LN((ARRAY(2)));
Before After
ARRAY(2) R(6,2,4) 10.00 10.00
RESULT R(6,2,4) 0.00 2.30
Errors
If the value of the parameter is zero or less, an error message is issued
to indicate a computational error has occurred.
LOG
The LOG function computes the common logarithm to the base 10 of a
number.
NOTE Previously, an additional set of parentheses was not allowed around
an item parameter in this function. This has been changed so that
additional parentheses around an item are optional. For example,
LOG(A) and LOG((A)) are both acceptable.
Syntax
LOG({(item-name[(subscript)])})
{numeric-constant }
Examples
LET (RESULT) = LOG(100.0);
Before After
RESULT R(6,2,4) 0.00 2.0
LET (RESULT) = LOG((ARRAY(2)));
Before After
ARRAY(2) R(6,2,4) 10.00 10.00
RESULT R(6,2,4) 0.00 1.00
Errors
If the value of the parameter is zero or less, an error message is issued
to indicate a computational error has occurred.
POSITION
The POSITION function returns the integer index of the position of the
first occurrence of the second string in the first string. Trailing
blanks in both strings are ignored. Hence, a string only consisting of
blanks cannot be found.
If no match is found, then 0 is returned. This function is case
sensitive (for example, "a" does not match "A").
This function is only valid for string constants and data items of type X
or U. The display length will be used when calculating the length of a
data it of type X or U.
Syntax
POSITION({(item-name1[(subscript)])},{(item-name2[(subscript)])})
{"character-string1" } {"character-string2" }
Examples
LET (INDEX) = POSITION("GOOD_DOG","Z");
Before After
INDEX I(5) 99 0
LET (INDEX) = POSITION((STRING1),"D");
Before After
STRING1 X(8) BAD_DOG_ BAD_DOG_
INDEX I(5) 99 3
NOTE In the following example note that the trailing blanks in both
arguments are ignored.
LET (INDEX) = POSITION((STRING1),(STRING2(4)));
Before After
STRING1 X(8) BANANA__ BANANA__
STRING2(4) X(4) NA__ NA__
INDEX I(5) 99 3
SQRT
The SQRT function computes the square root of a number.
NOTE Previously, an additional set of parentheses was not allowed around
an item parameter in this function. This has been changed so that
additional parentheses around an item are optional. For example,
SQRT(A) and SQRT((A)) are both acceptable.
Syntax
SQRT({(item-name[(subscript)])})
{numeric-constant }
Examples
LET (RESULT) = SQRT(100.0);
Before After
RESULT R(6,2,4) 0.00 10.00
LET (RESULT) = SQRT((ARRAY(2)));
Before After
ARRAY(2) I(5) 64 64
RESULT I(5) 0 8
Errors
If the value of the parameter is less than zero, an error message is
issued to indicate a computational error has occurred.
VALUE
The VALUE function returns the numerical value of a string containing the
character representation of an integer or a floating point number.
Leading blanks are ignored. An initial plus or minus sign is allowed.
The number is then terminated by one of the following: (1) the first
character that would not be valid in the number; (2) the end of the
defined length of the item; or (3) a delimiter defined via the
SET(DELIMITER) verb.
With Native Language Support, Transact validates numeric data using the
thousands and decimal indicators of the language in effect. (See
Appendix E, "Native Language Support," for more information.) If a
number is not represented in the string, then 0 is returned. Scientific
notation (type E) is not parsed in the string.
When searching through an item, the last character searched depends upon
the data type. For an X or U item, the display length is used to get the
last character. For an item defined as I, J, Z, P, K, R, or 9, the value
function operates in the same way as a LET assignment.
Syntax
VALUE({(item-name[(subscript)])})
{"character-string" }
Examples
LET (NUM) = VALUE("-3A");
Before After
NUM I(5) 0 -3
LET (NUM) = VALUE("__+43.21ABC");
Before After
NUM R(6,2,4) 0.0 43.21
LET (NUM) = VALUE((ARRAY(2)));
Before After
ARRAY(2) X(4) 42_3 42_3
NUM I(5) 0 42
LET (NUM) = VALUE("__A3A");
Before After
NUM I(5) 0 0
LET (NUM) = VALUE(".52Time");
Before After
NUM R(6,2,4) 0.0 0.52
LET (NUM) = VALUE(I);
Before After
NUM I(5) 0 12345
I I(5) 12345 12345
LET (NUM) = VALUE("123-456");
Before After
NUM I(5) 0 123
Syntax Options
(1) LET (variable)=[-]arithmetic-expression;
Choose this option to place a single value or the result of an arithmetic
operation into a location in the data register variable or into one of
the Transact-defined names allowed for the destination variable. The
following are examples of this syntax option:
LET (SUBTOTAL)=(SUBTOTAL) + (AMOUNT); <<Add values of AMOUNT and SUBTOTAL>>
<<and place result in SUBTOTAL >>
LET (PERCENT)=9.8; <<Set value of PERCENT to 9.8 >>
LET (INVERSE)=1/(DIVISOR); <<Calculate inverse value >>
LET (CNT)=-(CNT); <<Negate value of CNT >>
LET (DEDUCTION)=-[(SUBTOTAL)-(BENEFIT)]; <<The result of subtracting >>
<<BENEFIT from SUBTOTAL is >>
<<negated and placed in DEDUCTION>>
LET PAGE=200; <<Set page counter to 200 >>
LET LINE=60-(REMAINING-LINES); <<Calculate value of current line >>
LET (STAT) = STATUS; <<Set STAT to contents of status >>
<<register >>
LET STATUS = STATUS+1; <<Increment value of status register>>
LET STATUS = 0; <<Clear status register>>
<< Set UNIT-PRICE, but if an arithmetic error occurs, branch >>
<< to CALC-ERROR label and reset list register at UNIT-PRICE. >>
LET (UNIT-PRICE) = (SUBTOTAL-PRICE)/(QUANTITY),ERROR=CALC-ERROR(UNIT-PRICE);
NOTE The LET verb is primarily used to perform arithmetic operations on
numeric items. No error is generated if a character (X or U type)
item is used and processing continues for that character type, but
the results may not be as expected. (Use MOVE to handle character
items.)
When LET is used with character items, be aware that the display length
is used to determine the size of the item. If the destination item is
defined with a display length equal to or larger than the source, the
entire source is placed in the destination. If the destination is
defined with a display length smaller than the source, the source value
is truncated on the right when placed in the destination. The following
example demonstrates how different display lengths affect the result.
SYSTEM T6100;
DEFINE(ITEM) SMALL X(5,,6):
LARGE X(6,,6);
LIST SMALL:
LARGE;
<<LET uses the display length as the size of the item>>
MOVE (SMALL) = "12345"; <<Small has "12345 " in storage >>
DISPLAY SMALL; <<Small displays "12345" >>
LET (SMALL) = -(SMALL); <<Small has "-12345" in storage >>
DISPLAY SMALL; <<Small displays "-1234" >>
LET (LARGE) = (SMALL); <<Large has "-1234 " in storage >>
DISPLAY SMALL: LARGE; <<Both display "-1234" >>
EXIT;
(2) LET OFFSET(item-name)=[-]arithmetic-expression
(item-name) Identifies an ordinary data item or a child item.
[-]arithmetic - Is as defined earlier for the LET verb, except that
expression in this context the variables may not be
subscripted.
This option of the LET verb sets the value of OFFSET for a particular
item. It allows you to refer to a child item within a parent item by
telling Transact the byte location at which the item begins.
NOTE It is strongly recommended that you address array items by using
subscripts. This discussion is included for those dealing with
older versions of Transact programs written before subscripting of
arrays was implemented. In any case, the LET OFFSET and
subscripting should not be used together. Doing so may cause the
program to update the data registers in areas outside the limits of
the item referenced and could lead to unpredictable results. Since
this was previously the only way to manipulate arrays, no error
will be generated. (See "Array Subscripts" in Chapter 3.)
By changing the value of OFFSET, you can refer to any child item within
the parent item. Suppose an array and its child items are defined as
follows:
Initially, the OFFSET of YEAR within SALES is 0, which actually refers to
byte position 1 of SALES. That is, YEAR(1)= SALES(1), and, therefore,
YEAR refers to the first 10 bytes of SALES. To refer to other elements of
SALES, you must change the OFFSET of YEAR. You can do it as follows
(where element-size is expressed in bytes):
LET OFFSET(YEAR)=(element-number - 1) * element-size
For example, to point to the third element of SALES, which is 10 bytes
long, and then move a value to that element, use the following
statements:
LET OFFSET(YEAR)= 2 * 10; << (3rd element-1) * element size >>
MOVE (YEAR)=(VALUE-STRING);
To access and display the second and third positions, use the following
statements:
SYSTEM TEST;
DEFINE(ITEM) SALES 3X(10):
YEAR X(10)=SALES(1);
PROMPT SALES;
DISPLAY SALES;
DISPLAY YEAR;
LET OFFSET(YEAR)= 1 * 10; <<Access 2nd element of SALES (2-1) >>
DISPLAY YEAR;
LET OFFSET(YEAR)= 2 * 10; <<Access 3rd element of SALES (3-1) >>
DISPLAY YEAR;
END;
Note that the offset is counted from zero. Thus, to access the second
position in SALES, you specify an offset of 1; to access the third
position of SALES, you specify an offset of 2.
It is possible to step through a parent item using the following form of
the LET statement:
LET OFFSET(child-item)=OFFSET(child-item)+(byte-length-of-child-item)
For example, assuming the same array SALES, you can specify the next
child item as follows:
LET OFFSET(YEAR) = OFFSET(YEAR) + 10
You can also use the OFFSET option of LET to manipulate complex arrays.
Consider the complex array of sales figures shown in Figure 8-1. Its
compound items are district, year, and month. Each cell, which is a
child item, contains a sales figure in integer format. Note that each
value in each cell requires four bytes of storage.
This SALES matrix requires the following DEFINE(ITEM) statement:
DEFINE(ITEM) SALES-ARRAY X(144):
DIST 2 X(72) = SALES-ARRAY:
YEAR 3 X(24) = DIST:
MONTH 12 X(2) = YEAR:
SALES I(4,,2) = MONTH;
The fifth line of the DEFINE statement above redefines MONTH as SALES to
further identify the data being stored.
Figure 8-1. Complex Array of Sales Figures.
To locate the position of one SALES element within the array, you must
use three LET OFFSET statements. To locate the byte position of the
second district of the third year of the seventh month, use the following
three LET OFFSET statements:
LET OFFSET(DIST) = OFFSET(DIST) + 1 * 72;
LET OFFSET(YEAR) = OFFSET(YEAR) + 2 * 24;
LET OFFSET(MONTH) = OFFSET(MONTH) + 6 * 2;
Since OFFSET leaves the pointer at the last position referenced, it is
necessary to either reset the pointer before further manipulation or plan
the next OFFSET in terms of the current position. The following
statements reset all offsets to zero, representing the position
SALES(1,1,1).
LET OFFSET(DIST) = 0;
LET OFFSET(YEAR) = 0;
LET OFFSET(MONTH) = 0;
When assigning a value to an array, LET assigns each element in the array
to that value. If a subscript is specified, then only that element is
assigned the value. All other elements remain unchanged.
For example, ARRAY-A is defined as 4X(2), and ARRAY-B is defined as
4I(5,,2).
MOVE (TEMP-X) = "ND";
LET (ARRAY-A) = (TEMP-X); <<Sets all elements in ARRAY-A >>
DISPLAY ARRAY-A;
MOVE (TEMP-X) = "YR";
LET (ARRAY-A(2)) = (TEMP-X); <<Sets second elements only in ARRAY-A>>
DISPLAY ARRAY-A;
LET (ARRAY-B) = 67; <<Sets all elements in ARRAY-B >>
DISPLAY ARRAY-B;
LET (ARRAY-B(3)) = 78; <<Sets third element in ARRAY-B >>
DISPLAY ARRAY-B;
Rounding
To determine how rounding is done in Transact, it is necessary to
understand how Transact performs arithmetic operations. In general, if
you want arithmetic results to be rounded instead of truncated to a
desired precision, you should ensure that the [REV BEG]operands,
including constants, have at least one more digit of precision than the
desired result.[REV END]
Transact uses one of three different methods to process arithmetic
expressions. The three methods are:
* double integer arithmetic
* long real arithmetic
* packed decimal arithmetic
The first two methods, double integer and long real arithmetic, are used
only if the values meet particular criteria. When these criteria are not
met, the third method, packed decimal, is used by default. Since packed
decimal arithmetic is slower than the other two methods, it is advisable
to use variables that meet the criteria for one of the other two methods
whenever possible.
The factors that determine the method to be used are:
* Whether the expression consists of a single operation or multiple
operations.
* Data types of the destination variable and the operands.
* The number of decimal places defined for the destination variable
and the operands.
* Storage length of the destination variable and the operands.
32-Bit Integer Arithmetic
To qualify for 32-bit integer arithmetic, an expression must meet all of
the following conditions:
* The expression must consist of only one operation and that
operation can only be +, -, =, or unary minus.
* The data types of the destination variable and the operands must
be either I or J. Numeric constants cannot be used.
* The number of decimal places must be identical in target item and
both operands.
* Storage length of destination variable and all operands must be
16-bits.
When 32-bit integer arithmetic is used, the target item and the operands
are converted to 32-bit integers before the operation is performed. The
final result is rounded to the precision of the destination variable and
then converted back to a 16-bit integer. Although the operands are
converted to 32-bit integers before computation, the final result for
16-bit integers should lie between -32768 and 32767.
The following is an example of 32-bit integer arithmetic:
SYSTEM ARIT02;
DEFINE(ITEM) I1 I(4,1):
I2 I(4,1):
I3 I(4,1);
LIST I1:
I2:
I3;
LET (I1) = 45.99; << Packed decimal arithmetic >>
LET (I2) = 35.99; << Packed decimal arithmetic >>
LET (I3) = (I1) + (I2); << Double integer arithmetic >>
DISPLAY;
EXIT;
When the program is run, the values displayed are:
I1 = 46.0
I2 = 36.0
I3 = 82.0
64-Bit Real Arithmetic
To qualify for the 64-bit (long) real method of operation, the operands
must meet all of the following conditions:
* The expression must consist of a single operation which must be +,
-, *, /, //, =, unary minus, LN, LOG, SQRT, or **.
* The destination variable and the operands must all be of data type
R or E. Numeric constants can be used; they are converted to the
type of the destination variable.
* The storage length of all three variables should be 32-bit or
64-bit.
For 64-bit real arithmetic, if the destination variable and the operands
are not already 64-bit real, they are converted to 64-bit real before the
operation is performed. The final result is converted back to the size
of the destination variable. The internal value of the final item may
carry more precision than its defined decimal count. Hence, for
subsequent 64-bit real arithmetic, the internal value carrying more
precision will be used. On the other hand, for subsequent packed decimal
arithmetic (see the following discussion), the internal value will be
rounded according to the defined precision and then will be used. The
internal value will be rounded up for DISPLAY statements.
For example,
SYSTEM LONGRL;
DEFINE(ITEM) REAL1 R(8): << No decimal place. >>
REAL2 R(8,2):
REAL3 R(8,2);
LIST REAL1:
REAL2:
REAL3;
LET (REAL1) = 1440 / 900; << 64-Bit Real >>
The display value of REAL1 is 2 (rounded). Internally the value is
1.5555553436279 L+00.. In subsequent 64-bit real arithmetic, the
internal value of REAL1 1.555555..... will be used.
LET (REAL2) = (REAL1) + (REAL1);
In subsequent packed decimal arithmetic, REAL1 and REAL2 will be rounded
before computation.
LET (REAL3) = (REAL1) * (REAL2) / 3.11;
DISPLAY REAL1: REAL2: REAL3;
The values displayed are as follows:
REAL1 = 2
REAL2 = 3.11
REAL3 = 2.00
Packed Decimal Arithmetic
If the values in an expression do not meet the criteria for processing by
either the 32-bit integer or 64-bit real methods, then the packed decimal
method is used.
In this approach, an arithmetic expression is processed according to the
rules of precedence described earlier.
Before computation, the data types of the destination variable and
operands are converted to P - - packed P(27,0,14) - - if the operation is
+, -, *, /, //, =, or unary minus. For the remaining functions, such as
SQRT, LOG, LN, exponentiation, and so on, the operands and destination
variable are converted to 64-bit real. If this function is an
intermediate operation, the result is converted to data type P and
stacked for continuing with the rest of the expression. Any operands of
type R or E that carry greater precision due to previous long real
arithmetic are rounded according to the precision defined for packed
decimal arithmetic.
While an expression is being evaluated according to the rules of
precedence, each intermediate computational result is computed to the
highest precision of the two operands and the destination item. If the
precision of the expression is greater than the precision of the
destination item, the result is rounded to the precision of the
destination item. For example, 3.0/2.0 would produce 1.5 as an
intermediate result, which would round to 2 if stored in a receiving item
with no decimal places. Unlike COBOL, Transact does not maintain extra
precision just for rounding. Thus some division operations may result in
a loss of precision. For example, 3/2 produces 1 instead of 1.5 for an
intermediate result if the destination variable has no decimal precision.
To ensure that precision is not lost, either the receiving item must have
the desired precision (at least one decimal place greater than in the
arithmetic expression) or all operands in the entire expression must have
the desired precision. For applications that require the destination
variable to have fewer or zero decimal places, a two-step arithmetic
sequence is recommended. The destination variable of the first LET
should have an adequate number of decimal places for processing the whole
expression and then the second LET statement should contain a simple
assignment (=) to an integer item having fewer or zero decimal places.
The following example shows this technique.
SYSTEM PAKDEC;
DEFINE(ITEM) R1 R(6): << No decimal place >>
R2 R(11,5): << More decimal places >>
I3 I(9,2); << Fewer decimal places >>
Example 1
The LET statement below uses the destination variable R1, which has no
decimal places. Compare the final results with the next LET statement.
LET (R1) = 11590.0000 * [[6353.6100 / 6354] * [1440/900]];
| ____________ |
.9999
| ______ |
1
| _____________ |
.9999
| ____________________ |
11588.8410
| _________________ |
11589 (ROUNDED)
Example 2
The LET statement below uses the destination variable R2, which has five
decimal places.
LET (R2) = 11590.0000 * [[6353.6100 / 6354] * [1440/900]];
| ____________ |
.99993
| ______ |
1.60000
| _______________ |
1.59989
| ____________________ |
18542.72510
| ________________ |
18542.72510
The LET statement below does a simple assignment to the item I3, which
has two decimal places. The result is rounded. This is a packed decimal
operation, since data types are different. The internal value of I3 does
not carry extra precision.
LET (I3) = (R2);
| ______ |
18542.73 (ROUNDED)
[REV BEG]
The next two examples show the effect of using either 2 or 5 digits of
decimal precision on the first example above.[REV END]
[REV BEG]
Example 3
Suppose the following was included in the source file:
!PRECISION(2)
The original LET statement assigning a value to item R1 (Example 1) is
now evaluated as shown below. The major difference from the original
evaluation is that 1440/900 is treated as 1.60 rather than 1 which
affects all subsequent intermediate results.
LET (R1) = 11590.0000 * [[6353.6100 / 6354] * [1440/900]];
| ____________ |
.9999
| ______ |
1.60
| _____________ |
1.5998
| ____________________ |
18541.6820
| __________________ |
18542 (ROUNDED)
[REV END][REV BEG]
Example 4
Now replace the !PRECISION statement above with the following statement:
!PRECISION(5)
The original LET statement assigning a value to item R1 (Example 1) is
now evaluated as shown below. This LET statement is evaluated the same
as in Example 2, except that here it is rounded for the final assignment.
LET (R1) = 11590.0000 * [[6353.6100 / 6354] * [1440/900]];
| ____________ |
.99993
| ______ |
1.60000
| _____________ |
1.59989
| ____________________ |
18542.72510
| __________________ |
18543 (ROUNDED)
[REV END][REV BEG]
NOTE The result of the LET statement assigning a value to item R2 in
Example 2 is not altered by changing the minimum decimal precision
to either 2 or 5. Since the destination variable is defined with 5
decimal digits, all intermediate results automatically maintain at
least 5 digits of decimal precision.
For more information about !PRECISION, see "Compiler Commands" in Chapter
9.[REV END]
MPE/iX 5.5 Documentation