Abs class method

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: 0.1.x

class function Abs(const F: TFraction): TFraction; static;

Applies to: ~>0.2

class function Abs(const F: TFraction): TFraction; overload; static;
function Abs: TFraction; overload;

Description

Returns the absolute value of a fraction. The returned fraction is not simplified.

The class method operates on the fraction passed as parameter F.

[~>0.2] The instance method operates upon the fraction instance on which it is called.

Examples

Using the class method:

var
  F, G: TFraction;
begin
  F := TFraction.Create(3, 4);
  G := TFraction.Abs(F);
  Assert(G = +F);
  F := TFraction.Create(-7, 8);
  G := TFraction.Abs(F);
  Assert(G = -F);
end;

[~>0.2] Using the instance method:

var
  F, G: TFraction;
begin
  F := TFraction.Create(3, 4);
  G := F.Abs;
  Assert(G = +F);
  F := TFraction.Create(-7, 8);
  G := F.Abs;
  Assert(G = -F);
end;

See Also