Преглед на файлове

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

git-svn-id: trunk@38332 -
florian преди 7 години
родител
ревизия
8a2cf56d51
променени са 3 файла, в които са добавени 25 реда и са изтрити 0 реда
  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/tw33086.pp svneol=native#text/pascal
 tests/webtbs/tw3309.pp svneol=native#text/plain
 tests/webtbs/tw3309.pp svneol=native#text/plain
 tests/webtbs/tw33098.pp svneol=native#text/pascal
 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/tw3320.pp svneol=native#text/plain
 tests/webtbs/tw33202.pp svneol=native#text/pascal
 tests/webtbs/tw33202.pp svneol=native#text/pascal
 tests/webtbs/tw3324.pp svneol=native#text/plain
 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;
 operator mod(const a,b:float) c:float;inline;
 begin
 begin
   c:= a-b * Int(a/b);
   c:= a-b * Int(a/b);
+  if SameValue(abs(c),abs(b)) then
+    c:=0.0;
 end;
 end;
 
 
 function ifthen(val:boolean;const iftrue:integer; const iffalse:integer= 0) :integer;
 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.
+
+