Currency and Int64 casting

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Currency and Int64 casting

LacaK
Hi,

consider following program:

var
   c: currency;

begin
   c := 1;
   writeln(c,' ',Int64(c));
   readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Currency and Int64 casting

vojtech.cihak

Hi,

 

Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 

 1.000000000000000000E+00 10000

V.

______________________________________________________________
> Od: LacaK <[hidden email]>
> Komu: FPC-Pascal users discussions <[hidden email]>
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Currency and Int64 casting

LacaK

 

Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 

 1.000000000000000000E+00 10000

What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19            i1 := Int64(c);
0040158D a100c04200               mov    0x42c000,%eax
00401592 a310c04200               mov    %eax,0x42c010
00401597 a104c04200               mov    0x42c004,%eax
0040159C a314c04200               mov    %eax,0x42c014

and for Win64:
test_curr_int64.lpr:19                    i1 := Int64(c);
00000001000015BD 488b0d3caa0300           mov    0x3aa3c(%rip),%rcx        # 0x10003c000
00000001000015C4 48b84b598638d6c56d34     movabs $0x346dc5d63886594b,%rax
00000001000015CE 48f7e9                   imul   %rcx
00000001000015D1 48c1fa0b                 sar    $0xb,%rdx
00000001000015D5 48c1e93f                 shr    $0x3f,%rcx
00000001000015D9 4801ca                   add    %rcx,%rdx
00000001000015DC 4889152daa0300           mov    %rdx,0x3aa2d(%rip)        # 0x10003c010


L.

______________________________________________________________
> Od: LacaK [hidden email]
> Komu: FPC-Pascal users discussions [hidden email]
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Currency and Int64 casting

vojtech.cihak
In reply to this post by vojtech.cihak

Hi,

 

I have

unit1.pas:36                              i:=Int64(c);

000000000046EEE0 488b45e8                 mov    -0x18(%rbp),%rax

000000000046EEE4 488945e0                 mov    %rax,-0x20(%rbp)

unit1.pas:38                              writeln(i);

at Level0 and
unit1.pas:36                              i:=Int64(c);
000000000046EECD 4c8b2424                 mov    (%rsp),%r12
unit1.pas:38                              writeln(i);
at Level3.
I just noticed that you wrote you are expecting 1000. You should expect 10000 since currency has four decimals.
V. 

 

______________________________________________________________
> Od: LacaK <[hidden email]>
> Komu: [hidden email]
> Datum: 18.05.2018 07:54
> Předmět: Re: [fpc-pascal] Currency and Int64 casting
>


 

Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 

 1.000000000000000000E+00 10000

What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19            i1 := Int64(c);
0040158D a100c04200               mov    0x42c000,%eax
00401592 a310c04200               mov    %eax,0x42c010
00401597 a104c04200               mov    0x42c004,%eax
0040159C a314c04200               mov    %eax,0x42c014

and for Win64:
test_curr_int64.lpr:19                    i1 := Int64(c);
00000001000015BD 488b0d3caa0300           mov    0x3aa3c(%rip),%rcx        # 0x10003c000
00000001000015C4 48b84b598638d6c56d34     movabs $0x346dc5d63886594b,%rax
00000001000015CE 48f7e9                   imul   %rcx
00000001000015D1 48c1fa0b                 sar    $0xb,%rdx
00000001000015D5 48c1e93f                 shr    $0x3f,%rcx
00000001000015D9 4801ca                   add    %rcx,%rdx
00000001000015DC 4889152daa0300           mov    %rdx,0x3aa2d(%rip)        # 0x10003c010


L.

______________________________________________________________
> Od: LacaK [hidden email]
> Komu: FPC-Pascal users discussions [hidden email]
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



----------

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Currency and Int64 casting

LacaK

Than you,


 

I have

unit1.pas:36                              i:=Int64(c);

000000000046EEE0 488b45e8                 mov    -0x18(%rbp),%rax

000000000046EEE4 488945e0                 mov    %rax,-0x20(%rbp)

unit1.pas:38                              writeln(i);

at Level0 and
unit1.pas:36                              i:=Int64(c);
000000000046EECD 4c8b2424                 mov    (%rsp),%r12
unit1.pas:38                              writeln(i);
at Level3.
So we can clearly say, that x64_86 output is different on Linux and Windows64
It is at least strange from my POV because I would expect consistent results across platforms.

I just noticed that you wrote you are expecting 1000. You should expect 10000 since currency has four decimals.
Yes, it was typo. Of course I expect 10000

L.

V. 

 

______________________________________________________________
> Od: LacaK [hidden email]
> Komu: [hidden email]
> Datum: 18.05.2018 07:54
> Předmět: Re: [fpc-pascal] Currency and Int64 casting
>


 

Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 

 1.000000000000000000E+00 10000

What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19            i1 := Int64(c);
0040158D a100c04200               mov    0x42c000,%eax
00401592 a310c04200               mov    %eax,0x42c010
00401597 a104c04200               mov    0x42c004,%eax
0040159C a314c04200               mov    %eax,0x42c014

and for Win64:
test_curr_int64.lpr:19                    i1 := Int64(c);
00000001000015BD 488b0d3caa0300           mov    0x3aa3c(%rip),%rcx        # 0x10003c000
00000001000015C4 48b84b598638d6c56d34     movabs $0x346dc5d63886594b,%rax
00000001000015CE 48f7e9                   imul   %rcx
00000001000015D1 48c1fa0b                 sar    $0xb,%rdx
00000001000015D5 48c1e93f                 shr    $0x3f,%rcx
00000001000015D9 4801ca                   add    %rcx,%rdx
00000001000015DC 4889152daa0300           mov    %rdx,0x3aa2d(%rip)        # 0x10003c010


L.

______________________________________________________________
> Od: LacaK [hidden email]
> Komu: FPC-Pascal users discussions [hidden email]
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



----------

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Currency and Int64 casting

LacaK

Moreover:

var
  c: currency;
  i1: int64;
  i2: int64 absolute c;

begin
  c := 68719476736;
  i1 := Trunc(c*10000);
  writeln(c,', ',i1,', ',i2);
  readln;
end.

Win32 (as expected):  6.871947673600000000E+10, 687194767360000, 687194767360000
Win64 (wrong)          :  6.871947673600000000E+10, 53550614319         , 687194767360000

L.

Than you,


 

I have

unit1.pas:36                              i:=Int64(c);

000000000046EEE0 488b45e8                 mov    -0x18(%rbp),%rax

000000000046EEE4 488945e0                 mov    %rax,-0x20(%rbp)

unit1.pas:38                              writeln(i);

at Level0 and
unit1.pas:36                              i:=Int64(c);
000000000046EECD 4c8b2424                 mov    (%rsp),%r12
unit1.pas:38                              writeln(i);
at Level3.
So we can clearly say, that x64_86 output is different on Linux and Windows64
It is at least strange from my POV because I would expect consistent results across platforms.

I just noticed that you wrote you are expecting 1000. You should expect 10000 since currency has four decimals.
Yes, it was typo. Of course I expect 10000

L.

V. 

 

______________________________________________________________
> Od: LacaK [hidden email]
> Komu: [hidden email]
> Datum: 18.05.2018 07:54
> Předmět: Re: [fpc-pascal] Currency and Int64 casting
>


 

Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 

 1.000000000000000000E+00 10000

What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19            i1 := Int64(c);
0040158D a100c04200               mov    0x42c000,%eax
00401592 a310c04200               mov    %eax,0x42c010
00401597 a104c04200               mov    0x42c004,%eax
0040159C a314c04200               mov    %eax,0x42c014

and for Win64:
test_curr_int64.lpr:19                    i1 := Int64(c);
00000001000015BD 488b0d3caa0300           mov    0x3aa3c(%rip),%rcx        # 0x10003c000
00000001000015C4 48b84b598638d6c56d34     movabs $0x346dc5d63886594b,%rax
00000001000015CE 48f7e9                   imul   %rcx
00000001000015D1 48c1fa0b                 sar    $0xb,%rdx
00000001000015D5 48c1e93f                 shr    $0x3f,%rcx
00000001000015D9 4801ca                   add    %rcx,%rdx
00000001000015DC 4889152daa0300           mov    %rdx,0x3aa2d(%rip)        # 0x10003c010


L.

______________________________________________________________
> Od: LacaK [hidden email]
> Komu: FPC-Pascal users discussions [hidden email]
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



----------

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Currency and Int64 casting

LacaK

> Moreover:
>
> var
>   c: currency;
>   i1: int64;
>   i2: int64 absolute c;
>
> begin
>   c := 68719476736;
>   i1 := Trunc(c*10000);
>   writeln(c,', ',i1,', ',i2);
>   readln;
> end.
>
> Win32 (as expected):  6.871947673600000000E+10, 687194767360000,
> 687194767360000
> Win64 (wrong)          :  6.871947673600000000E+10,
> 53550614319         , 687194767360000
>
I have created bug report:
https://bugs.freepascal.org/view.php?id=33758

> L.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal