Title: Adding some FORTRAN Functions
Question: Where are the Floating point functions that I was use to in FORTRAN like Ceil, Floor, Rem and Mod?
Answer:
Whilst Delphi gives us Integer Mod, many of us who grew up with Languages like FORTRAN miss the float functions such as Ceil, Floor, Mod and Rem. Long before Delphi added a Math Unit, we used the following:
function ESBCeil (const X: Extended): Extended;
begin
Result := Int (X);
if Result Result := Result + 1.0;
end;
function ESBFloor (const X: Extended): Extended;
begin
Result := Int (X);
if Result X then
Result := Result - 1.0;
end;
function ESBMod (const X, Y: Extended): Extended;
begin
if FloatIsZero (Y) then
raise EMathError.Create ('Y cannot be 0 in ESBMod!')
else
Result := X - ESBFloor (X / Y) * Y
end;
function ESBRem (const X, Y: Extended): Extended;
begin
if FloatIsZero (Y) then
raise EMathError.Create ('Y cannot be 0 in ESBRem!')
else
Result := X - Int (X / Y) * Y
end;
For FloatIsZero see my other Article on Rounding.