View Issue Details

IDProjectCategoryView StatusLast Update
0035886FPCCompilerpublic2019-07-28 14:04
ReporterMarcelo Campos RochaAssigned ToJonas Maebe 
Status resolvedResolutionfixed 
Product Version3.2.0Product Build 
Target VersionFixed in Version3.3.1 
Summary0035886: Casting Int64 to Double doesn't convert on mode Delphi
DescriptionThe Release notes from FPC 3.0( describes a new behavior where
explicit typecasting from Int64 to Double results in a conversion. I've observed that this behavior happens on objfpc mode, but not on delphi mode. It's not the expected, because Delphi's compiler does the same conversion when doing explicit typecasting.
Steps To Reproduceprogram project1;

{$mode objfpc}


  f: Double;
  n: Int64;

  n := 9876543210;
  f := Double(n);
TagsNo tags attached.
Fixed in Revision42507
Attached Files


related to 0006660 closedJonas Maebe Variable typecasts 


Thaddy de Koning

2019-07-26 11:20

reporter   ~0117412

Confirmed. The behavior is different from delphi.
There is a delphi compatible work-around:
program project1;
{$mode delphi}

  f: Double;
  n: Int64;

  n := 9876543210;
  f := n.ToDouble;

Thaddy de Koning

2019-07-26 11:22

reporter   ~0117413

Possibly because sysutils is compiled in {$mode objfpc}

Jonas Maebe

2019-07-27 18:16

manager   ~0117438

Last edited: 2019-07-28 00:02

View 2 revisions

It behaved like that in Turbo Pascal (with single/longint; it did not have an int64 type), and I guess the assumption was made it would be the same in Delphi, or maybe it did behave the same in early Delphi versions. However, Kylix 3 (= Delphi 6.5) refuses to compile it altogether, claiming it's an invalid type cast. Given this bug report, I suppose current Delphi versions do accept it?

Thaddy de Koning

2019-07-27 20:30

reporter   ~0117439

I will try to determine in which version of Delphi it changed. I tested with Berlin, but can test against everything below and including XE2 too.
I will report back. If it is in e.g. D7 like this, the behavior should be changed for mode Delphi.

Bart Broersma

2019-07-27 23:58

reporter   ~0117446

D7 says it's an invalid typecast.

jamie philbrook

2019-07-28 00:32

reporter   ~0117447

What am I missing here?

Does ADouble := AInt64 not work?

 I have a old version of Delphi (3) handy and type casting a Double around a comp or currency does exactly what I would expect it to, it compiles fine and returns the actual binary content of the COMP/CURRENT as if it was a float but not the value I define them as, which is what I would expect.

 Int64 should be the same size as the double, (8 bytes) which it is, the only known cast I know of where the compiler should flag an error is if the casting is known to be larger than the item being casted in memory usage.

  since my old D3 has no issues directly setting a Double from a COMP or Currency which are int64's the same should work here too?

 Please tell me what I am missing ?

Thaddy de Koning

2019-07-28 10:36

reporter   ~0117452

Last edited: 2019-07-28 11:30

View 5 revisions

What you are missing is that a cast to double in mode delphi returns the bit pattern as double and mode objfpc returns a double representation of the int64 value.
e.g. Delphi 10.3 returns 1.23456000000000E+0005 for a Double(123456) cast and not the bitpattern, (6.0995368372976933E-319) that {$mode delphi} returns. {$Mode objfpc} returns the about the same value as Delphi 10.3, slightly differs: 1.2345600000000000E+005. Note that when the same code would be used in mode delphi as in mode objfpc, the scaling still differs.

Jonas Maebe

2019-07-28 13:16

manager   ~0117455

FPC in Delphi mode now behaves the same as an FPC modes (and modern Delphi versions).

Issue History

Date Modified Username Field Change
2019-07-25 15:08 Marcelo Campos Rocha New Issue
2019-07-26 11:20 Thaddy de Koning Note Added: 0117412
2019-07-26 11:22 Thaddy de Koning Note Added: 0117413
2019-07-27 18:16 Jonas Maebe Note Added: 0117438
2019-07-27 20:28 Jonas Maebe Assigned To => Jonas Maebe
2019-07-27 20:28 Jonas Maebe Status new => assigned
2019-07-27 20:30 Thaddy de Koning Note Added: 0117439
2019-07-27 23:58 Bart Broersma Note Added: 0117446
2019-07-28 00:02 Jonas Maebe Note Edited: 0117438 View Revisions
2019-07-28 00:32 jamie philbrook Note Added: 0117447
2019-07-28 10:36 Thaddy de Koning Note Added: 0117452
2019-07-28 10:41 Thaddy de Koning Note Edited: 0117452 View Revisions
2019-07-28 10:42 Thaddy de Koning Note Edited: 0117452 View Revisions
2019-07-28 11:30 Thaddy de Koning Note Edited: 0117452 View Revisions
2019-07-28 11:30 Thaddy de Koning Note Edited: 0117452 View Revisions
2019-07-28 13:16 Jonas Maebe Status assigned => resolved
2019-07-28 13:16 Jonas Maebe Resolution open => fixed
2019-07-28 13:16 Jonas Maebe Fixed in Version => 3.3.1
2019-07-28 13:16 Jonas Maebe Fixed in Revision => 42507
2019-07-28 13:16 Jonas Maebe FPCTarget => -
2019-07-28 13:16 Jonas Maebe Note Added: 0117455
2019-07-28 14:04 Jonas Maebe Relationship added related to 0006660