mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 21:39:21 +02:00
MulDiv:
- use math rounding instead of bank rounding (by Grzegorz Zakrzewski) - return -1 if Denominator is 0 (as winapi do) (issue #0009934) git-svn-id: trunk@12831 -
This commit is contained in:
parent
f007970067
commit
07d4573f3a
@ -2564,6 +2564,7 @@ type
|
|||||||
function HiWord(i: integer): word;
|
function HiWord(i: integer): word;
|
||||||
function LoWord(i: integer): word;
|
function LoWord(i: integer): word;
|
||||||
Function Char2VK(C : Char) : Word;
|
Function Char2VK(C : Char) : Word;
|
||||||
|
function MathRound(AValue: ValReal): Int64;
|
||||||
function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
|
function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
|
||||||
function KeyToShortCut(const Key: Word; const Shift: TShiftState): TShortCut;
|
function KeyToShortCut(const Key: Word; const Shift: TShiftState): TShortCut;
|
||||||
function CharSetToString(const Charset: Integer): String;
|
function CharSetToString(const Charset: Integer): String;
|
||||||
@ -2583,7 +2584,7 @@ begin
|
|||||||
Result:=Lo(i);
|
Result:=Lo(i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function Char2VK(C : Char) : Word;
|
function Char2VK(C : Char) : Word;
|
||||||
begin
|
begin
|
||||||
Case C of
|
Case C of
|
||||||
'0'..'9' :Result := VK_0 + Ord(C) - Ord('0');
|
'0'..'9' :Result := VK_0 + Ord(C) - Ord('0');
|
||||||
@ -2594,9 +2595,20 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function MathRound(AValue: ValReal): 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;
|
function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
Result:=Round(int64(nNumber)*int64(nNumerator) / nDenominator);
|
if nDenominator = 0 then
|
||||||
|
Result := -1
|
||||||
|
else
|
||||||
|
Result := MathRound(int64(nNumber) * int64(nNumerator) / nDenominator);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function KeyToShortCut(const Key: Word; const Shift: TShiftState): TShortCut;
|
function KeyToShortCut(const Key: Word; const Shift: TShiftState): TShortCut;
|
||||||
|
Loading…
Reference in New Issue
Block a user