Browse Source

pastojs: jsvalue:=currency

git-svn-id: trunk@38808 -
Mattias Gaertner 7 years ago
parent
commit
73310ac57f

+ 4 - 4
packages/fcl-passrc/src/pasresolveeval.pas

@@ -290,13 +290,13 @@ const
   HighIntAsUInt = MaxPrecUInt(High(MaxPrecInt));
   HighIntAsUInt = MaxPrecUInt(High(MaxPrecInt));
 
 
 const
 const
-  MinSafeIntCurrency = -922337203685477;
-  MaxSafeIntCurrency =  922337203685477;
+  MinSafeIntCurrency = -922337203685477; // .5808
+  MaxSafeIntCurrency =  922337203685477; // .5807
   MinSafeIntSingle = -16777216;
   MinSafeIntSingle = -16777216;
   MaxSafeIntSingle =  16777216;
   MaxSafeIntSingle =  16777216;
   MaskUIntSingle = $3fffff;
   MaskUIntSingle = $3fffff;
-  MinSafeIntDouble = -$10000000000000;
-  MaxSafeIntDouble =   $fffffffffffff;
+  MinSafeIntDouble = -$10000000000000; // -4503599627370496
+  MaxSafeIntDouble =   $fffffffffffff; //  4503599627370495
   MaskUIntDouble = $fffffffffffff;
   MaskUIntDouble = $fffffffffffff;
 
 
 type
 type

+ 1 - 0
packages/pastojs/src/fppas2js.pp

@@ -322,6 +322,7 @@ Works:
   - CurA^^CurB -> Math.floor(Math.pow(CurA/10000,CurB/10000)*10000)
   - CurA^^CurB -> Math.floor(Math.pow(CurA/10000,CurB/10000)*10000)
   - Double:=Currency  ->  Double:=Currency/10000
   - Double:=Currency  ->  Double:=Currency/10000
   - Currency:=Double  -> Currency:=Math.floor(Double*10000)
   - Currency:=Double  -> Currency:=Math.floor(Double*10000)
+  - jsvalue := currency  ->  jsvalue:=currency/10000
 - simplify Math.floor(number) to trunc(number)
 - simplify Math.floor(number) to trunc(number)
 
 
 ToDos:
 ToDos:

+ 9 - 0
packages/pastojs/tests/tcmodules.pas

@@ -4944,8 +4944,10 @@ begin
   '  c: TCoin = b;',
   '  c: TCoin = b;',
   '  i: nativeint;',
   '  i: nativeint;',
   '  d: double;',
   '  d: double;',
+  '  j: jsvalue;',
   'function DoIt(c: currency): currency; begin end;',
   'function DoIt(c: currency): currency; begin end;',
   'function GetIt(d: double): double; begin end;',
   'function GetIt(d: double): double; begin end;',
+  'procedure Write(v: jsvalue); begin end;',
   'begin',
   'begin',
   '  c:=1.0;',
   '  c:=1.0;',
   '  c:=0.1;',
   '  c:=0.1;',
@@ -4983,6 +4985,8 @@ begin
   '  c:=DoIt(i);',
   '  c:=DoIt(i);',
   '  c:=DoIt(d);',
   '  c:=DoIt(d);',
   '  c:=GetIt(c);',
   '  c:=GetIt(c);',
+  '  j:=c;',
+  '  Write(c);',
   '']);
   '']);
   ConvertProgram;
   ConvertProgram;
   CheckSource('TestCurrency',
   CheckSource('TestCurrency',
@@ -4994,6 +4998,7 @@ begin
     'this.c = $mod.b;',
     'this.c = $mod.b;',
     'this.i = 0;',
     'this.i = 0;',
     'this.d = 0.0;',
     'this.d = 0.0;',
+    'this.j = undefined;',
     'this.DoIt = function (c) {',
     'this.DoIt = function (c) {',
     '  var Result = 0;',
     '  var Result = 0;',
     '  return Result;',
     '  return Result;',
@@ -5002,6 +5007,8 @@ begin
     '  var Result = 0.0;',
     '  var Result = 0.0;',
     '  return Result;',
     '  return Result;',
     '};',
     '};',
+    'this.Write = function (v) {',
+    '};',
     '']),
     '']),
     LinesToStr([
     LinesToStr([
     '$mod.c = 10000;',
     '$mod.c = 10000;',
@@ -5040,6 +5047,8 @@ begin
     '$mod.c = $mod.DoIt($mod.i * 10000);',
     '$mod.c = $mod.DoIt($mod.i * 10000);',
     '$mod.c = $mod.DoIt($mod.d * 10000);',
     '$mod.c = $mod.DoIt($mod.d * 10000);',
     '$mod.c = Math.floor($mod.GetIt($mod.c / 10000) * 10000);',
     '$mod.c = Math.floor($mod.GetIt($mod.c / 10000) * 10000);',
+    '$mod.j = $mod.c / 10000;',
+    '$mod.Write($mod.c / 10000);',
     '']));
     '']));
 end;
 end;
 
 

+ 20 - 0
utils/pas2js/docs/translation.html

@@ -38,6 +38,7 @@
     <a href="#variables">Translating variables</a><br>
     <a href="#variables">Translating variables</a><br>
     <a href="#string">Translating string</a><br>
     <a href="#string">Translating string</a><br>
     <a href="#resourcestrings">Translating resourcestrings</a><br>
     <a href="#resourcestrings">Translating resourcestrings</a><br>
+    <a href="#currency">Translating currency</a><br>
     <a href="#types">Translating types</a><br>
     <a href="#types">Translating types</a><br>
     <a href="#pointer">Translating pointer</a><br>
     <a href="#pointer">Translating pointer</a><br>
     <a href="#record">Translating record</a><br>
     <a href="#record">Translating record</a><br>
@@ -546,6 +547,25 @@ End.
     </table>
     </table>
     </div>
     </div>
 
 
+    <div class="section">
+    <h2 id="currency">Translating currency</h2>
+    <i>Currency</i> in Delphi/FPC is an int64 with a factor of 10000. This is
+    translated to a rounded double with factor 10000.
+    <ul>
+      <li><i>CurA := 1.1</i> -> <i>CurA = 11000</i></li>
+      <li><i>CurA + CurB</i> -> <i>CurA + CurB</i></li>
+      <li><i>CurA * CurB</i> -> <i>CurA * CurB/10000</i></li>
+      <li><i>CurA / CurB</i> -> <i>Math.floor(CurA/CurB * 10000)</i></li>
+      <li><i>CurA ^^ CurB</i> -> <i>Math.floor(Math.pow(CurA/10000,CurB/10000) * 10000)</i></li>
+      <li><i>Currency + Double</i> -> <i>Currency + (Double*10000)</i></li>
+      <li><i>Double := Currency</i> -> <i>Double = Currency/10000</i></li>
+      <li><i>Currency := Double</i> -> <i>Currency = Math.floor(Double*10000)</i></li>
+      <li><i>JSValue := Currency</i> -> <i>JSValue = Currency/10000</i></li>
+      <li>Keep in mind that a double has only 52 bits for the number, so calculating
+      values greater than 450,359,962,737 might give a different result than in Delphi/FPC.</li>
+    </ul>
+    </div>
+
     <div class="section">
     <div class="section">
     <h2 id="types">Translating Types</h2>
     <h2 id="types">Translating Types</h2>
     JavaScript type design has no declarative form, except for object types
     JavaScript type design has no declarative form, except for object types