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.

Negative operator overload

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

class operator Negative(const F: TFraction): TFraction;

Description

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.

Example

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;

See Also