Project: Fractions
Unit: DelphiDabbler.Lib.Fractions
Record: TFraction
Applies to: ~>0.1
function HasCommonFactor(const Factor: Int64): Boolean;
This method checks if a given value is a common factor for the fraction. The value being queried is passed in the Factor parameter.
A common factor is an integer that exactly divides both the numerator and denominator of a fraction.
The method always returns False if Factor is zero.
HasCommonFactor is useful for checking that a value is a valid common factor before passing to Simplify method.
var
F: TFraction;
S: string;
CF: Int64;
begin
F := TFraction.Create(32, 48);
// get common factor from user
S := _;
if not InputQuery('HasCommonFactor', 'Enter a factor', S) then
Exit;
CF := StrToInt64Def(S, 0);
if F.HasCommonFactor(CF) then
ShowMessageFmt(
'%d is a common factor of %d/%d', [CF, F.Numerator, F.Denominator]
);
end;