Project: Fractions
Unit: DelphiDabbler.Lib.Fractions
Record: TFraction
Applies to: ~>0.1
class operator Equal(const A, B: TFraction): Boolean;
This operator overload permits TFractions to be tested for equality using the = operator.
Two fractions are considered equal if they can be simplified to the same fraction. For example 1/2 = 2/4. Formally, two fractions are equal if their 1st and 2nd cross products are equal.
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.
var
F1, F2, F3, F4: TFraction;
D: Double;
I: Integer;
begin
F1 := TFraction.Create(1, 4);
F2 := TFraction.Create(1, 4);
F3 := TFraction.Create(2, 8);
F4 := TFraction.Create(3, 1);
D := 0.25;
I := 3;
Assert(F1 = F2);
Assert(F1 = F3);
Assert(D = F1);
Assert(F1 = D);
Assert(I = F4);
Assert(F4 = I);
end;