Jelajahi Sumber

* prefer typecast currency->extended over currency->single/double because the former loses no precision while the latter might cause a loss of precision, resolves #19077

git-svn-id: trunk@17297 -
florian 14 tahun lalu
induk
melakukan
ff6ab60508
3 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/defcmp.pas
  3. 13 0
      tests/webtbs/tw19077.pp

+ 1 - 0
.gitattributes

@@ -11282,6 +11282,7 @@ tests/webtbs/tw1896.pp svneol=native#text/plain
 tests/webtbs/tw1901.pp svneol=native#text/plain
 tests/webtbs/tw1901.pp svneol=native#text/plain
 tests/webtbs/tw1902.pp svneol=native#text/plain
 tests/webtbs/tw1902.pp svneol=native#text/plain
 tests/webtbs/tw1907.pp svneol=native#text/plain
 tests/webtbs/tw1907.pp svneol=native#text/plain
+tests/webtbs/tw19077.pp svneol=native#text/pascal
 tests/webtbs/tw1908.pp svneol=native#text/plain
 tests/webtbs/tw1908.pp svneol=native#text/plain
 tests/webtbs/tw1909.pp svneol=native#text/plain
 tests/webtbs/tw1909.pp svneol=native#text/plain
 tests/webtbs/tw1910.pp svneol=native#text/plain
 tests/webtbs/tw1910.pp svneol=native#text/plain

+ 2 - 1
compiler/defcmp.pas

@@ -564,7 +564,8 @@ implementation
                            begin
                            begin
                              doconv:=tc_real_2_real;
                              doconv:=tc_real_2_real;
                              { do we lose precision? }
                              { do we lose precision? }
-                             if def_to.size<def_from.size then
+                             if (def_to.size<def_from.size) or
+                               (is_currency(def_from) and (tfloatdef(def_to).floattype in [s32real,s64real])) then
                                eq:=te_convert_l2
                                eq:=te_convert_l2
                              else
                              else
                                eq:=te_convert_l1;
                                eq:=te_convert_l1;

+ 13 - 0
tests/webtbs/tw19077.pp

@@ -0,0 +1,13 @@
+uses
+  math;
+var
+  c : currency;
+begin
+  c:=1.5625;
+  c:=RoundTo(c,-1);
+  if c<>1.6 then
+    halt(1);
+  writeln('ok');
+end.
+
+