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.

Sign method

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

function Sign: TValueSign;

Description

This method returns a value representing the sign of the fraction. The return values are:

These values are constants defined in the Math unit as High(TValueSign), 0 and Low(TValueSign) respectively. TValueSign is itself defined as -1..1.

Example

var
  F: TFraction;
begin
  F := TFraction.Create(2, 3);
  Assert(F.Sign = Math.PositiveValue);
  F := 0;
  Assert(F.Sign = Math.ZeroValue);
  F := TFraction.Create(-2, 3);
  Assert(F.Sign = Math.NegativeValue);
end;

Note

You can also check the sign by using the overloaded =, > and < operators to compare a TFraction to zero, as in:

var
  F: TFraction;
begin
  // set up F here
  if F > 0 then
    // positive
  else if F < 0 then
    // negative
  else
  begin
    Assert(F = 0);
    // zero
  end;

See Also