Browse Source

* fixed operator mod for floats as proposed by wp in #33167, resolves #33167

git-svn-id: trunk@38332 -
florian 7 năm trước cách đây
mục cha
commit
8a2cf56d51
3 tập tin đã thay đổi với 25 bổ sung0 xóa
  1. 1 0
      .gitattributes
  2. 2 0
      rtl/objpas/math.pp
  3. 22 0
      tests/webtbs/tw33167.pp

+ 1 - 0
.gitattributes

@@ -16016,6 +16016,7 @@ tests/webtbs/tw33069.pp svneol=native#text/pascal
 tests/webtbs/tw33086.pp svneol=native#text/pascal
 tests/webtbs/tw3309.pp svneol=native#text/plain
 tests/webtbs/tw33098.pp svneol=native#text/pascal
+tests/webtbs/tw33167.pp svneol=native#text/pascal
 tests/webtbs/tw3320.pp svneol=native#text/plain
 tests/webtbs/tw33202.pp svneol=native#text/pascal
 tests/webtbs/tw3324.pp svneol=native#text/plain

+ 2 - 0
rtl/objpas/math.pp

@@ -2440,6 +2440,8 @@ end;
 operator mod(const a,b:float) c:float;inline;
 begin
   c:= a-b * Int(a/b);
+  if SameValue(abs(c),abs(b)) then
+    c:=0.0;
 end;
 
 function ifthen(val:boolean;const iftrue:integer; const iffalse:integer= 0) :integer;

+ 22 - 0
tests/webtbs/tw33167.pp

@@ -0,0 +1,22 @@
+{$ifndef FPUNONE}
+uses
+  math;
+
+var
+  a,b,c : double;
+begin
+  a:=7.7;
+  b:=1.1;
+  c:=a mod b;
+  if not(SameValue(c,0.0)) then
+    begin
+      writeln(c);
+      halt(1);
+    end;
+  writeln('ok');
+{$else FPUNONE}
+begin
+{$endif FPUNONE}
+end.
+
+