• Aucun résultat trouvé

DECLARE LIST (4) STRUCTURE (KEY BYTE, INFO (3) WORD);

Dans le document GUIDE PL/M-86 (Page 111-115)

then LENGTH(RECORD.INFO) is a valid function reference and returns a WORD value of 3.

If the array is a member of a structure, and the structure is an element of an array, a special case arises. Given the declaration:

DECLARE LIST (4) STRUCTURE (KEY BYTE, INFO (3) WORD);

then all of the following function references are correct and return the value 3:

LENGTH(LIST(O).INFO) LENGTH(LIST(1).INFO) LENGTH(LIST(2).INFO) LENGTH(LIST(3).INFO)

In other words, the subscript for the array LIST is irrelevant when a member-identifier is supplied, since the arrays within the structures are all the same length.

Built-In Procedures, Functions, and Variables PL/M-86 User's Guide

11-2

PL/M-86 allows a "shorthand" form of partially qualified variable reference in the LENGTH, LAST, and SIZE function refer~nces. For example:

lENGTH(lIST.INFO)

is a valid function reference and returns the value 3.

The LAST Function

LAST is a WORD function that returns the subscript of the last element in an array.

It is activated by a function reference, with the form:

lAS T

(variable-ref)

where variable-ref must be a non-subscripted reference to an array.

The array may be a member of a structure; it may not be the MEMORY array (see section 11.6), or an EXTERNAL array using the implicit dimension specifier (see section 3.2).

The WORD value returned is the subscript of the last element of the array-note that for a given array, LAST will always be one less than LENGTH.

As in the LENGTH function, a "shorthand" form of partially qualified variable reference is allowed in the case where the array is a member of a structure and the structure is an array element.

The SIZE Function

SIZE is a WORD function that returns the number of bytes occupied by an array or structure. It is activated by a function reference, with the form:

S I Z E (variable-ref)

where variable-ref is a fully qualified, partially qualified, or unqualified reference to any scalar, array, or structure except the MEMORY array (see section 11.6). It may not be an EXTERNAL declaration that uses the implicit dimension specifier (see section 3.2).

The WORD value returned is the number of bytes required by the object referenced.

If the reference is fully qualified, it refers to a scalar and the value is the number of bytes required for the scalar. If the reference is unqualified, it refers to an entire structure or array, and the value is the total number of bytes required for the struc-ture or array.

If the reference is partially qualified, it refers either to a structure member that is an array, or to an array element that is a structure. The value is the number of bytes required for the array or structure.

As in the LENGTH function, a "shorthand" form of partially qualified variable reference is allowed in the case where the array or scalar is a member of a structure and the structure is an array element.

11.2 Explicit Type and Value Conversions

The ten functions in this section provide explicit conversion from one type to another and from signed values to or from absolute magnitudes.

PL/M-86 User's Guide Built-In Procedures, Functions, and Variables

Explicit type-conversion functions are invoked function .. name (expression)

where the function has a type and the expression a value.

In table 11-1, each function name is followed by its type, the expression type expected, the purpose of the function, and the nature of the value it returns to the expression that invoked it.

Proced.ure

Table 11-1. Explicit Type and Value Conversion

Parameter Expression

Name Type Type Function Result Returned

LOW BYTE BYTE Converts WORD value to

Converts WORD value to 0 (zero)

BYTE value High-order byte of WORD DOUBLE WORD DWORD Converts DWORD value High-order word of DWORD REAL INTEGER Converts INTEGER value Same value of type REAL

to REAL value

Converts REAL value to INTEGER value modulo 32768, INTEGER value i.e., within range ±32767

(rounds toward zero)

Converts BYTE or WORD Corresponding INTEGER value to INTEGER; interprets within range 0 to 32767

parameter as positive

WORD INTEGER Converts an INTEGER value to a WORD value

Absolute value of expression supplied. If positive, returned unchanged; if negative, -(expression) is returned.

Absolute value of expression supplied. If positive, returned unchanged; if negative, -(expression) is returned.

Built-In Procedures, Functions, and Variables PL/M-86 User's Guide

11-4

The LOW, HIGH, and DOUBLE Functions

LOW and HIGH are BYTE functions that convert WORD values to BYTE values, or WORD functions that convert DWORD values to WORD values. They are activated by function references with the forms:

LOW (expression) H I G H (expression)

where expression has a DWORD, WORD, or BYTE value.

If expression has a DWORD value, LOW returns the value of the low-order (least significant) word of the expression value, whereas HIGH returns the value of the high-order (most significant) word of the expression value.

If expression has a WORD value, LOW returns the value of the low-order (least significant) byte of the expression value, whereas HIGH returns the value of the high-order (most significant) byte of the expression value.

If expression has a BYTE value, then LOW will return this value unchanged.

However, HIGH will return O.

DOUBLE is a WORD function that converts a BYTE value to a WORD value or a DWORD function that converts a word value to a DWORD value. It is activated by a function reference with the form:

DO U B L E (expression)

where expression has a BYTE, WORD, or DWORD value.

If expression has a BYTE value, the function appends 8 high-order O-bits to convert it to a WORD value and returns this WORD value. If expression has a WORD value, the function appends 16 high-order zero bits to convert it to a DWORD value and returns this value. If expression has a DWORD value, the function returns it unchanged.

The FLOAT Function

FLOAT is a REAL function that converts an INTEGER value to a REAL value. It is activated by a function reference, with the form:

FLO A T (expression)

where expression has an INTEGER value.

FLOA T converts the INTEGER value to the corresponding REAL value and returns this REAL value.

The FIX Function

FIX is an INTEGER function that converts a REAL value to an INTEGER value. It is activated by a function reference, with the form:

F I X (expression)

where expression has a REAL value.

PL/M-86 User's Guide Built-In Procedures, Functions, and Variables

FIX rounds the REAL value to the nearest INTEGER. If both INTEGERs are equally near, FIX rounds to the even one. The resulting INTEGER value is then returned. Thus FIX(1.4) would result in the INTEGER value 1, FIX(-1.8) in -2, FIX(3.5) in 4, and FIX(6.5) in 6.

If the result calculated by FIX is not within the implemented range of INTEGER values, the result is undefined.

NOTE

FIX is affected by your choice of rounding mode-see Chapter 13. the above examples assume the default mode, which is "round to nearest or even."

Dans le document GUIDE PL/M-86 (Page 111-115)