Project: Fractions
Unit: DelphiDabbler.Lib.Fractions
Record: TFraction
Applies to: ~>0.1
class operator Trunc(const F: TFraction): Int64;
The operator overload enables the Trunc “operator” or compiler function to operate on a TFraction. The operator truncates the fraction to the nearest whole number in the direction of zero.
var
F: TFraction;
begin
F := TFraction.Create(17, 3);
Assert(Trunc(F) = 5);
F := TFraction.Create(-58, 7);
Assert(Trunc(F) = -8);
F := TFraction.Create(3, 1);
Assert(Trunc(F) = 3);
F := TFraction.Create(-3, 1);
Assert(Trunc(F) = -3);
F := TFraction.Create(0, 1);
Assert(Trunc(F) = 0);
end;