Project: Fractions
Unit: DelphiDabbler.Lib.Fractions
Record: TFraction
Applies to: ~>0.1
class operator Multiply(const A, B: TFraction): TFraction;
This operator overload permits two TFractions to be multiplied together using the * operator.
The result of the multiplication is returned as a new TFraction instance, reduced to its lowest terms.
One of the operands may be either an integer or floating point value. The Implicit operator takes care of converting the integer and floating point operands to a TFraction before performing the multiplication.
var
F1, F2, FRes: TFraction;
begin
// 3/4 * 2/3 = 6/12 = 1/2
F1 := TFraction.Create(3, 4);
F2 := TFraction.Create(2, 3);
FRes := F1 * F2;
Assert((FRes.Numerator = 1) and (FRes.Denominator = 2));
// 2 * 5/6 = 2/1 * 5/6 = 10/6 = 5/3
F2 := TFraction.Create(5, 6);
FRes := 2 * F2;
Assert((FRes.Numerator = 5) and (FRes.Denominator = 3));
// 5/6 * 2.5 = 5/6 * 5/2 = 25/12
F1 := TFraction.Create(5, 6);
FRes := F1 * 2.5;
Assert((FRes.Numerator = 25) and (FRes.Denominator = 12));
end;