Browse Source

* when creating a realconstn, cast the value to the specified type
(mantis #25121)
o note that this means that single_const1/single_const2 will now be rounded
to single, instead of staying the at maximum precision
o fixed FahrenheitToCelcius() to handle this change correctly

git-svn-id: trunk@37911 -

Jonas Maebe 7 years ago
parent
commit
8cfe7e0a0c
4 changed files with 25 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 15 0
      compiler/ncon.pas
  3. 1 1
      packages/rtl-objpas/src/inc/stdconvs.pp
  4. 8 0
      tests/webtbs/tw25121.pp

+ 1 - 0
.gitattributes

@@ -15466,6 +15466,7 @@ tests/webtbs/tw25059.pp svneol=native#text/pascal
 tests/webtbs/tw25077.pp svneol=native#text/pascal
 tests/webtbs/tw25081.pp svneol=native#text/pascal
 tests/webtbs/tw25101.pp svneol=native#text/pascal
+tests/webtbs/tw25121.pp svneol=native#text/plain
 tests/webtbs/tw25122.pp svneol=native#text/plain
 tests/webtbs/tw25132.pp svneol=native#text/pascal
 tests/webtbs/tw2514.pp svneol=native#text/plain

+ 15 - 0
compiler/ncon.pas

@@ -337,6 +337,21 @@ implementation
             internalerror(2008022401);
          inherited create(realconstn);
          typedef:=def;
+         case tfloatdef(def).floattype of
+           s32real:
+             v:=single(v);
+           s64real:
+             v:=double(v);
+           s80real,
+           sc80real,
+           s64comp,
+           s64currency:
+             v:=extended(v);
+           s128real:
+             internalerror(2013102701);
+           else
+             internalerror(2013102702);
+         end;
          value_real:=v;
          value_currency:=v;
          lab_real:=nil;

+ 1 - 1
packages/rtl-objpas/src/inc/stdconvs.pp

@@ -199,7 +199,7 @@ implementation
 
 function FahrenheitToCelsius(const AValue: Double): Double;
 begin
-  result:= (5.0/9.0)  * (Avalue - 32.0);
+  result:= (double(5.0)/9.0)  * (Avalue - 32.0);
 end;
 
 function CelsiusToFahrenheit(const AValue: Double): Double;

+ 8 - 0
tests/webtbs/tw25121.pp

@@ -0,0 +1,8 @@
+begin
+  if not(single(144115188075855877) = single(144115188075855872)) then
+    halt(1);
+  if not(single(1 / 3.0) = single(0.33333333)) then
+    halt(2);
+  if not(single(92233720368547758) = single(92233720000000000)) then
+    halt(3);
+end.