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.

GreaterThan operator overload

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

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

Description

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

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

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(F2 > F1);
  Assert(F3 > F2);
  Assert(F3 > F1);
  Assert(D > F1);
  Assert(F2 > D);
  Assert(F3 > D);
  Assert(I > F1);
  Assert(I > F2);
  Assert(F3 > I);
end;

See Also