Reputation: 783
This works as one might expect running on our local machines:
var
c : Currency;
f : Double;
begin
f := 0.12345;
c := Currency(f);
OutputDebugString(PChar(FloatToStrF(c, ffNumber, 18, 4)));
end;
Debug Output: 0,1235
On our CI machine we get:
Debug Output: 459.355.993.064.714,7130
Why is that?
Upvotes: 2
Views: 684
Reputation: 783
We noticed a seemingly undocumented behavioral change between Delphi Berlin and Tokyo, the latter running on our machines and the former on our CI server. Explicit cast from double to currency does not behave as one might expect in versions up to Berlin:
MyFormU.pas.43: f := 0.12345;
005CE74D C745D07CF2B050 mov [ebp-$30],$50b0f27c
005CE754 C745D46B9ABF3F mov [ebp-$2c],$3fbf9a6b
MyFormU.pas.44: c := Currency(f);
005CE75B 8B45D0 mov eax,[ebp-$30]
005CE75E 8945E0 mov [ebp-$20],eax
005CE761 8B45D4 mov eax,[ebp-$2c]
005CE764 8945E4 mov [ebp-$1c],eax
MyFormU.pas.45: c2 := f;
005CE767 DD45D0 fld qword ptr [ebp-$30]
005CE76A D80D80E85C00 fmul dword ptr [$005ce880]
005CE770 DF7DD8 fistp qword ptr [ebp-$28]
005CE773 9B wait
Notice the implicit cast does the proper fp multiplication to convert the double to an Int64 (Currency is stored as such), whilst the explicit cast does not.
From Tokyo onwards the generated asm is the same for both casts.
Upvotes: 2