Hi there,
I just wanted to use MulDiv, and my initial reflex was just take it , but:
It seems not to be there in Systems, Math or the other, only in Winapi.Windows is the Windows version.
I would bet my left finger that MulDiv should be there, am I missing something.
The only thing I can find, from older messages, like this:
function MathRound(AValue: Extended): Int64; inline;
begin
if AValue >= 0 then
Result := Trunc(AValue + 0.5)
else
Result := Trunc(AValue - 0.5);
end;
function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
begin
if nDenominator = 0 then
Result := -1
else
Result := MathRound(Int64(nNumber) * Int64(nNumerator) / nDenominator);
end;
That looks a way over the top to me, why do they need floating point ?
I will use it like this:
function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
begin
if nDenominator = 0 then
Result := -1
else
Result := (Int64(nNumber) * Int64(nNumerator)) div nDenominator);
end;
But much better if someone can tell me where can I find a cross-platform, optimized version in the RTL ?