Array bounds and validation functions
These functions inspect arrays and validate values at runtime.
Array bounds
Section titled “Array bounds”| Function | Parameters | Returns |
|---|---|---|
LOWER_BOUND | ARR : ARRAY, DIM : ANY_INT | ANY_INT |
UPPER_BOUND | ARR : ARRAY, DIM : ANY_INT | ANY_INT |
DIM is the 1-based dimension number. These are especially useful with
conformant arrays (ARRAY[*]), where the bounds are not known until runtime —
see derived types.
LOWER_BOUND(ARR : ARRAY, DIM : ANY_INT) : ANY_INTUPPER_BOUND(ARR : ARRAY, DIM : ANY_INT) : ANY_INTFOR i := LOWER_BOUND(data, 1) TO UPPER_BOUND(data, 1) DO sum := sum + data[i];END_FOR;Validation
Section titled “Validation”| Function | Parameters | Returns |
|---|---|---|
IS_VALID | IN : ANY_REAL | BOOL |
IS_VALID_BCD | IN : ANY_BIT | BOOL |
IS_VALID returns FALSE for NaN/infinite floating-point values;
IS_VALID_BCD checks that a bit string holds a valid BCD-encoded value.
IS_VALID(IN : ANY_REAL) : BOOLIS_VALID_BCD(IN : ANY_BIT) : BOOLIF IS_VALID(measurement) THEN average := (average + measurement) / 2.0; // skip NaN/Inf readingsEND_IF
IF IS_VALID_BCD(thumbwheel) THEN value := BYTE_BCD_TO_INT(thumbwheel);END_IF