浏览代码

* more overloads for Math.Min/Max, resolves #36161

git-svn-id: trunk@43366 -
florian 5 年之前
父节点
当前提交
5ead23513d
共有 3 个文件被更改,包括 78 次插入0 次删除
  1. 1 0
      .gitattributes
  2. 37 0
      rtl/objpas/math.pp
  3. 40 0
      tests/webtbs/tw36161.pp

+ 1 - 0
.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

+ 37 - 0
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

+ 40 - 0
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.