Skip to content

Int64→Currency conversion is broken in Win64→Win32 cross-compiler.

This code:

var
	x, xtBack: currency;
	xt: int64;

begin
	x := 7.9 + random(0);
	writeln('x = ', x);

	xt := trunc(x);
	writeln('trunc(x) = ', xt);

	xtBack := xt;
	writeln('currency(trunc(x)) = ', xtBack);
end.

If compiled as Win64→Win64 or Win32→Win32, outputs correct

x =                  7.900000000000000000E+00
trunc(x) =           7
currency(trunc(x)) = 7.000000000000000000E+00

But if cross-compiled from Win64 to Win32, it outputs

x =                  7.900000000000000000E+00
trunc(x) =           7
currency(trunc(x)) = 0.000000000000000000E+00

I found this as soon as I tried to implement TCurrencyHelper.Floor/Ceil missing from !365 (merged) in the following way, very straightforward and efficient, but only when it works:

function TCurrencyHelper.Ceil: int64;
begin
	Result:=System.Trunc(Self);
	if Currency(Result)<Self then
		Result:=Result+1;
end;

function TCurrencyHelper.Floor: int64;
begin
	Result:=System.Trunc(Self);
	if Currency(Result)>Self then
		Result:=Result-1;
end;
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information