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.

LessThanOrEqual operator overload

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

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

Description

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

One fraction is considered to be less than or equal to a second if the 1st cross product of the two fractions is less than or equal to their 2nd cross product. Here are two examples:

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, F4, F5: TFraction;
  D: Double;
  I: Integer;
begin
  F1 := TFraction.Create(1, 2);
  F2 := TFraction.Create(3, 4);
  F3 := TFraction.Create(6, 8);
  F4 := TFraction.Create(1, 1);
  F5 := TFraction.Create(15, 8);
  D := 0.75;
  I := 1;
  Assert(F1 <= F2);  // 1/2 < 3/4
  Assert(F2 <= F3);  // 3/4 = 6/8
  Assert(F1 <= D);   // 1/2 < 0.75
  Assert(F2 <= D);   // 3/4 = 0.75
  Assert(D <= F3);   // 0.76 = 6/8
  Assert(D <= F5);   // 0.75 < 15/8
  Assert(F1 <= I);   // 1/2 < 1
  Assert(F4 <= I);   // 1/1 = 1
  Assert(I <= F4);   // 1 = 1/1
  Assert(I <= F5);   // 1 < 15/8
end;

See Also