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.

GreaterThanOrEqual operator overload

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

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

Description

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

One fraction is considered to be greater than or equal to a second if the 1st cross product of the two fractions is greater 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(F2 >= F1);  // 3/4 > 1/2
  Assert(F3 >= F2);  // 6/8 = 3/4
  Assert(D >= F1);   // 0.75 > 1/2
  Assert(D >= F2);   // 0.75 = 3/4
  Assert(F3 >= D);   // 6/8 = 0.75
  Assert(F5 >= D);   // 15/8 > 0.75
  Assert(I >= F1);   // 1 > 1/2
  Assert(I >= F4);   // 1 = 1/1
  Assert(F4 >= I);   // 1/1 = 1
  Assert(F5 >= I);   // 15/8 > 1
end;

See Also