DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

MinMidMax (Double overload)

Finds the minimum, middle and maximum values of three double precision floating point numbers, A, B and C and returns them in Min, Mid and Max respectively.

procedure MinMidMax(const A, B, C: Double; out Min, Mid, Max: Double); overload;
var
  Temp: Double;
begin
  if A > B then
  begin
    Max := A;
    Min := B;
  end
  else
  begin
    Max := B;
    Min := A;
  end;
  if C > Max then
  begin
    Mid := Max;
    Max := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end
  else
  begin
    Mid := Min;
    Min := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end;
end;

MinMidMax (Extended overload)

Finds the minimum, middle and maximum values of three extended precision floating point numbers, A, B and C and returns them in Min, Mid and Max respectively.

procedure MinMidMax(const A, B, C: Extended; out Min, Mid, Max: Extended); 
  overload;
var
  Temp: Extended;
begin
  if A > B then
  begin
    Max := A;
    Min := B;
  end
  else
  begin
    Max := B;
    Min := A;
  end;
  if C > Max then
  begin
    Mid := Max;
    Max := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end
  else
  begin
    Mid := Min;
    Min := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end;
end;

MinMidMax (Int64 overload)

Finds the minimum, middle and maximum values of three 64 bit integers, A, B and C and returns them in Min, Mid and Max respectively.

procedure MinMidMax(const A, B, C: Int64; out Min, Mid, Max: Int64); overload;
var
  Temp: Int64;
begin
  if A > B then
  begin
    Max := A;
    Min := B;
  end
  else
  begin
    Max := B;
    Min := A;
  end;
  if C > Max then
  begin
    Mid := Max;
    Max := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end
  else
  begin
    Mid := Min;
    Min := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end;
end;

MinMidMax (Integer overload)

Finds the minimum, middle and maximum values of three integers, A, B and C and returns them in Min, Mid and Max respectively.

procedure MinMidMax(const A, B, C: Integer; out Min, Mid, Max: Integer);
  overload;
var
  Temp: Integer;
begin
  if A > B then
  begin
    Max := A;
    Min := B;
  end
  else
  begin
    Max := B;
    Min := A;
  end;
  if C > Max then
  begin
    Mid := Max;
    Max := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end
  else
  begin
    Mid := Min;
    Min := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end;
end;

MinMidMax (Single overload)

Finds the minimum, middle and maximum values of three single precision floating point numbers, A, B and C and returns them in Min, Mid and Max respectively.

procedure MinMidMax(const A, B, C: Single; out Min, Mid, Max: Single); overload;
var
  Temp: Single;
begin
  if A > B then
  begin
    Max := A;
    Min := B;
  end
  else
  begin
    Max := B;
    Min := A;
  end;
  if C > Max then
  begin
    Mid := Max;
    Max := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end
  else
  begin
    Mid := Min;
    Min := C;
    if Mid < Min then
    begin
      Temp := Mid;
      Mid := Min;
      Min := Temp;
    end;
  end;
end;

View the whole database.

Go to the DelphiDabbler website.