CogniPilot

MODELICA LIBRARY · ENGINEERING REFERENCE

function

MathUtilities.clip

Clamp a scalar to a closed interval

Public declarations

Explicit source declarations; dimensions, modifications and defaults are shown as written, without evaluation.

RoleNameTypeDimensions / attributes / defaultDescription
inputvalueRealValue to clamp
inputlowerRealLower interval bound
inputupperRealUpper interval bound
outputresultRealClamped value

Modelica declarations and implementation

Show parameters, interfaces and source

Parameters, inputs, outputs, defaults and equations from the source file.

function clip "Clamp a scalar to a closed interval"
  input Real value "Value to clamp";
  input Real lower "Lower interval bound";
  input Real upper "Upper interval bound";
  output Real result "Clamped value";
algorithm
  result := min(max(value, lower), upper);
  annotation(Inline = true);
end clip;