Project: Fractions
Unit: DelphiDabbler.Lib.Fractions
Record: TFraction
Applies to: ~>0.1
class operator Negative(const F: TFraction): TFraction;
This operator overload enables the unary negative (negation) operator - to be applied to a TFraction.
The operator returns a copy of the fraction with its sign changed.
var
F, FNeg: TFraction;
begin
F := TFraction.Create(3, 4);
FNeg := -F;
Assert((FNeg.Numerator = -3) and (FNeg.Denominator = 4));
F := TFraction.Create(-3, 4);
FNeg := -F;
Assert((FNeg.Numerator = 3) and (FNeg.Denominator = 4));
F := TFraction.Create(0, 1);
FNeg := -F;
Assert((FNeg.Numerator = 0) and (FNeg.Denominator = 1));
end;