Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

LessThan operator overload

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

class operator LessThan(const A, B: TFraction): Boolean;

Description

This operator overload permits two TFractions to be compared using the < (less than) operator.

One fraction is considered to be less than a second if the 1st cross product of the two fractions is less than the 2nd cross product. Take for example 3/4 and 7/8. Their 1st cross product is 3 × 8 = 24 and their 2nd cross product is 4 × 7 = 28. Since 24 < 28, 3/4 is less than 7/8.

A TFraction can also be compared to integer and floating point types using the < operator. The Implicit operator takes care of converting the integer and floating point operands to TFraction before performing the comparison.

Example

var
  F1, F2, F3: TFraction;
  D: Double;
  I: Integer;
begin
  F1 := TFraction.Create(1, 2);
  F2 := TFraction.Create(3, 4);
  F3 := TFraction.Create(5, 4);
  D := 0.6;
  I := 1;
  Assert(F1 < F2);
  Assert(F2 < F3);
  Assert(F1 < F3);
  Assert(F1 < D);
  Assert(D < F2);
  Assert(D < F3);
  Assert(F1 < I);
  Assert(F2 < I);
  Assert(I < F3);
end;

See Also