Project: Fractions
Unit: DelphiDabbler.Lib.Fractions
Record: TFraction
Applies to: ~>0.1
function Sign: TValueSign;
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.
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;
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;