From 5ead23513d29a185a71dfa0fc3f5314e4fc7aad5 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 2 Nov 2019 16:21:43 +0000 Subject: [PATCH] * more overloads for Math.Min/Max, resolves #36161 git-svn-id: trunk@43366 - --- .gitattributes | 1 + rtl/objpas/math.pp | 37 +++++++++++++++++++++++++++++++++++++ tests/webtbs/tw36161.pp | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tests/webtbs/tw36161.pp diff --git a/.gitattributes b/.gitattributes index 8aae5d880f..c7b8f11319 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17849,6 +17849,7 @@ tests/webtbs/tw36013.pp svneol=native#text/pascal tests/webtbs/tw3612.pp svneol=native#text/plain tests/webtbs/tw36156.pp svneol=native#text/plain tests/webtbs/tw36157.pp svneol=native#text/plain +tests/webtbs/tw36161.pp svneol=native#text/pascal tests/webtbs/tw3617.pp svneol=native#text/plain tests/webtbs/tw3619.pp svneol=native#text/plain tests/webtbs/tw36196.pp svneol=native#text/pascal diff --git a/rtl/objpas/math.pp b/rtl/objpas/math.pp index c391cf448f..f8658603ec 100644 --- a/rtl/objpas/math.pp +++ b/rtl/objpas/math.pp @@ -167,6 +167,10 @@ function Min(a, b: Int64): Int64;inline; overload; function Max(a, b: Int64): Int64;inline; overload; function Min(a, b: QWord): QWord;inline; overload; function Max(a, b: QWord): QWord;inline; overload; +function Min(a: Int64; b: Qword): Int64;inline; overload; +function Min(a: Qword; b: Int64): Int64;inline; overload; +function Max(a: Int64; b: Qword): QWord;inline; overload; +function Max(a: Qword; b: Int64): QWord;inline; overload; {$ifdef FPC_HAS_TYPE_SINGLE} function Min(a, b: Single): Single;inline; overload; function Max(a, b: Single): Single;inline; overload; @@ -2075,6 +2079,39 @@ begin end; {$ifdef FPC_HAS_TYPE_SINGLE} + +function Min(a: Int64; b: Qword): Int64;inline; +begin + if a<0 then + Result:=a + else + Result:=Min(QWord(a),b); +end; + +function Min(a: Qword; b: Int64): Int64;inline; +begin + if b<0 then + Result:=b + else + Result:=Min(a,QWord(b)); +end; + +function Max(a: Int64; b: Qword): QWord;inline; +begin + if a<0 then + Result:=b + else + Result:=Max(QWord(a),b); +end; + +function Max(a: Qword; b: Int64): QWord;inline; +begin + if b<0 then + Result:=a + else + Result:=Max(a,QWord(b)); +end; + function Min(a, b: Single): Single;inline; begin if a < b then diff --git a/tests/webtbs/tw36161.pp b/tests/webtbs/tw36161.pp new file mode 100644 index 0000000000..d240bf3129 --- /dev/null +++ b/tests/webtbs/tw36161.pp @@ -0,0 +1,40 @@ +{ %OPT=-O1 } +program Project1; +uses Math; +var + t: Qword; + i: int64; +begin + i:=-12345687; + t:=QWord($a000000000000000); + if Min(sizeof(t), t)<>sizeof(t) then + halt(1); + if Min(t, sizeof(t))<>sizeof(t) then + halt(2); + if Min(t, i)<>i then + halt(3); + if Min(i, t)<>i then + halt(4); + if Min(sizeof(t),sizeof(t))<>sizeof(t) then + halt(5); + if Min(t,t)<>t then + halt(6); + if Min(i,i)<>i then + halt(7); + + if Max(sizeof(t), t)<>t then + halt(11); + if Max(t, sizeof(t))<>t then + halt(12); + if Max(i, t)<>t then + halt(13); + if Max(t, i)<>t then + halt(14); + if Max(sizeof(t),sizeof(t))<>sizeof(t) then + halt(15); + if Max(t,t)<>t then + halt(16); + if Max(i,i)<>i then + halt(17); + writeln('ok'); +end.