Attention

IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.

V4002

Code

V4002

Message

Negative exponent in arithmetic operation

The program attempted to raise a value to a negative exponent using the EXPT function. IEC 61131-3 integer exponentiation does not support negative exponents.

Example

The following code will generate error V4002:

PROGRAM Main
VAR
    x : INT := 5;
    result : INT;
END_VAR
result := EXPT(x, -2);  (* Error: negative exponent *)
END_PROGRAM

The exponent -2 is negative, which is not supported for integer exponentiation.

To fix this error, ensure the exponent is non-negative:

PROGRAM Main
VAR
    x : INT := 5;
    exp : INT := 2;
    result : INT;
END_VAR
IF exp >= 0 THEN
    result := EXPT(x, exp);
END_IF;
END_PROGRAM