mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 01:09:27 +02:00
pastojs: jsvalue:=currency
git-svn-id: trunk@38808 -
This commit is contained in:
parent
5e32960f33
commit
73310ac57f
@ -290,13 +290,13 @@ const
|
||||
HighIntAsUInt = MaxPrecUInt(High(MaxPrecInt));
|
||||
|
||||
const
|
||||
MinSafeIntCurrency = -922337203685477;
|
||||
MaxSafeIntCurrency = 922337203685477;
|
||||
MinSafeIntCurrency = -922337203685477; // .5808
|
||||
MaxSafeIntCurrency = 922337203685477; // .5807
|
||||
MinSafeIntSingle = -16777216;
|
||||
MaxSafeIntSingle = 16777216;
|
||||
MaskUIntSingle = $3fffff;
|
||||
MinSafeIntDouble = -$10000000000000;
|
||||
MaxSafeIntDouble = $fffffffffffff;
|
||||
MinSafeIntDouble = -$10000000000000; // -4503599627370496
|
||||
MaxSafeIntDouble = $fffffffffffff; // 4503599627370495
|
||||
MaskUIntDouble = $fffffffffffff;
|
||||
|
||||
type
|
||||
|
@ -322,6 +322,7 @@ Works:
|
||||
- CurA^^CurB -> Math.floor(Math.pow(CurA/10000,CurB/10000)*10000)
|
||||
- Double:=Currency -> Double:=Currency/10000
|
||||
- Currency:=Double -> Currency:=Math.floor(Double*10000)
|
||||
- jsvalue := currency -> jsvalue:=currency/10000
|
||||
- simplify Math.floor(number) to trunc(number)
|
||||
|
||||
ToDos:
|
||||
|
@ -4944,8 +4944,10 @@ begin
|
||||
' c: TCoin = b;',
|
||||
' i: nativeint;',
|
||||
' d: double;',
|
||||
' j: jsvalue;',
|
||||
'function DoIt(c: currency): currency; begin end;',
|
||||
'function GetIt(d: double): double; begin end;',
|
||||
'procedure Write(v: jsvalue); begin end;',
|
||||
'begin',
|
||||
' c:=1.0;',
|
||||
' c:=0.1;',
|
||||
@ -4983,6 +4985,8 @@ begin
|
||||
' c:=DoIt(i);',
|
||||
' c:=DoIt(d);',
|
||||
' c:=GetIt(c);',
|
||||
' j:=c;',
|
||||
' Write(c);',
|
||||
'']);
|
||||
ConvertProgram;
|
||||
CheckSource('TestCurrency',
|
||||
@ -4994,6 +4998,7 @@ begin
|
||||
'this.c = $mod.b;',
|
||||
'this.i = 0;',
|
||||
'this.d = 0.0;',
|
||||
'this.j = undefined;',
|
||||
'this.DoIt = function (c) {',
|
||||
' var Result = 0;',
|
||||
' return Result;',
|
||||
@ -5002,6 +5007,8 @@ begin
|
||||
' var Result = 0.0;',
|
||||
' return Result;',
|
||||
'};',
|
||||
'this.Write = function (v) {',
|
||||
'};',
|
||||
'']),
|
||||
LinesToStr([
|
||||
'$mod.c = 10000;',
|
||||
@ -5040,6 +5047,8 @@ begin
|
||||
'$mod.c = $mod.DoIt($mod.i * 10000);',
|
||||
'$mod.c = $mod.DoIt($mod.d * 10000);',
|
||||
'$mod.c = Math.floor($mod.GetIt($mod.c / 10000) * 10000);',
|
||||
'$mod.j = $mod.c / 10000;',
|
||||
'$mod.Write($mod.c / 10000);',
|
||||
'']));
|
||||
end;
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
<a href="#variables">Translating variables</a><br>
|
||||
<a href="#string">Translating string</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="#pointer">Translating pointer</a><br>
|
||||
<a href="#record">Translating record</a><br>
|
||||
@ -546,6 +547,25 @@ End.
|
||||
</table>
|
||||
</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">
|
||||
<h2 id="types">Translating Types</h2>
|
||||
JavaScript type design has no declarative form, except for object types
|
||||
|
Loading…
Reference in New Issue
Block a user