Skip to content

32 and 64 bit compiler return different results for same calculation with currency types.

Summary

32 and 64 bit compiler return different results for same calculation with currency types. There is 2 errors.

  1. The 64-bit compiler always truncates the results to 4 digits after decimal separator even when the result variable is double but 32-bit compiler doesn't truncate it. Why different behavior, why not same? 32-bit compiler is good here.
  2. The 64-bit compiler always truncates the results to 4 digits after decimal separator even when all variables are currency but the 32-bit compiler round it. Again why different behavior, why not same?

We discussed it on german forum

Look at my comments in example application:

Click to expand `program rundungsfehlerfpc1; {$mode objfpc}{$H+}

uses
Classes, SysUtils, Math;

function ShowVariable(const Value: Double): Double;
begin
writeln('Value: ',Format('%.6f', [Value]));
Result := Value;
end;

var
Netto, Brutto: Double;
Netto1, Brutto1: Currency;
begin
Netto:= 0.3738; // Brutto muss 0.4000 sein mit 7 MwSt.

Brutto:= ShowVariable(Netto * 1.07); // Okay, Value is for both 0,399966 because variables are double
writeln('Brutto: ',Format('%.6f', [Brutto]));

writeln('');

Netto1:= 0.3738; // Brutto muss 0.4000 sein

Brutto1:= ShowVariable(Netto1 * 1.07); // Error 1! The variable Value is with 32Bit 0,399966
// and with the 64Bit compiler 0,3999. Why not same?
writeln('Brutto: ',Format('%.6f', [Brutto1]));

writeln('');

Brutto1:= (Netto1 * 1.07); // Error 2! All variables are currency
// and Brutto1 is with the 32bit-compiler 0,4
// but with the 64bit-compiler 0,3999
// Again all variables are currency.
// Why different value?
writeln('Brutto: ',Format('%.6f', [Brutto1]));

ReadLn;
end. `

System Information

  • Operating system: Windows.
  • Processor architecture: x86, x86-64
  • Compiler version: 3.2.3 (3.2_fixes branch from today)
  • Device: Computer

Steps to reproduce

Try the example from zip file.

Example Project

currencyerror.zip

What is the current bug behavior?

different results for same calculation.

What is the expected (correct) behavior?

same result.

Relevant logs and/or screenshots

Possible fixes

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information