MAX

Returns the larger of two inputs.

Signature

     ┌─────────┐
IN1 ─┤         │
     │   MAX   ├─ OUT
IN2 ─┤         │
     └─────────┘
FUNCTION MAX : ANY
  VAR_INPUT
    IN1 : ANY;
    IN2 : ANY;
  END_VAR
END_FUNCTION

The return type matches the input type. MAX accepts SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT, REAL, LREAL. Both inputs must share the same type.

Inputs

Name

Type

Description

IN1

ANY_MAGNITUDE

The first value to compare.

IN2

ANY_MAGNITUDE

The second value to compare.

Outputs

Name

Type

Description

Return value

ANY_MAGNITUDE

The larger of IN1 and IN2. If both inputs are equal, returns that value. Same type as the inputs.

Description

Returns the larger of IN1 and IN2. If both inputs are equal, the function returns that value.

Example

result := MAX(10, 20);    (* result = 20 *)
result := MAX(-5, 3);     (* result = 3 *)

See Also

  • MIN — minimum of two values

  • LIMIT — clamp to range

  • SEL — binary selection

References