Bläddra i källkod

* fix trealconstnode.dogetcopy and trealconstnode.docompare, taking care of all fields, resolves #23486

git-svn-id: trunk@23241 -
florian 12 år sedan
förälder
incheckning
f6b78719bc
3 ändrade filer med 30 tillägg och 4 borttagningar
  1. 1 0
      .gitattributes
  2. 18 4
      compiler/ncon.pas
  3. 11 0
      tests/webtbs/tw23486.pp

+ 1 - 0
.gitattributes

@@ -13085,6 +13085,7 @@ tests/webtbs/tw2332.pp svneol=native#text/plain
 tests/webtbs/tw23342.pp svneol=native#text/pascal
 tests/webtbs/tw23436.pp svneol=native#text/plain
 tests/webtbs/tw23447.pp svneol=native#text/pascal
+tests/webtbs/tw23486.pp svneol=native#text/pascal
 tests/webtbs/tw23503.pp svneol=native#text/pascal
 tests/webtbs/tw2351.pp svneol=native#text/plain
 tests/webtbs/tw2363.pp svneol=native#text/plain

+ 18 - 4
compiler/ncon.pas

@@ -572,6 +572,7 @@ implementation
          n : trealconstnode;
       begin
          n:=trealconstnode(inherited dogetcopy);
+         n.typedef:=typedef;
          n.value_real:=value_real;
          n.value_currency:=value_currency;
          n.lab_real:=lab_real;
@@ -596,10 +597,23 @@ implementation
       begin
         docompare :=
           inherited docompare(p) and
-          (value_real = trealconstnode(p).value_real) and
-          { floating point compares for non-numbers give strange results usually }
-          is_number_float(value_real) and
-          is_number_float(trealconstnode(p).value_real);
+          { this should be always true }
+          (trealconstnode(p).typedef.typ=floatdef) and (typedef.typ=floatdef) and
+          (tfloatdef(typedef).floattype = tfloatdef(trealconstnode(p).typedef).floattype) and
+          (
+           (
+            (tfloatdef(typedef).floattype=s64currency) and
+            (value_currency=trealconstnode(p).value_currency)
+           )
+           or
+           (
+            (tfloatdef(typedef).floattype<>s64currency) and
+            (value_real = trealconstnode(p).value_real) and
+            { floating point compares for non-numbers give strange results usually }
+            is_number_float(value_real) and
+            is_number_float(trealconstnode(p).value_real)
+           )
+          );
       end;
 
 

+ 11 - 0
tests/webtbs/tw23486.pp

@@ -0,0 +1,11 @@
+{ %OPT=-O3 -Oocse }
+program project1;
+
+var
+  S: Single;
+  I: Integer;
+begin
+  S := 400;
+  I := 600;
+  writeln(Round((I / 2) - (S / 2)));
+end.