Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-02

Wrong floating point Currency calculations

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ondrej Pokorny

Hello,

when doing floating point calculations with Currency, the results are wrong.

Example:

program Project1;
var
   C0, C1, C2: Currency;
   D0: Double;
begin
   C0 := 4736;
   D0 := C0;
   C1 := C0 * 8 / 72 * 25.4 / 2048;
   C2 := D0 * 8 / 72 * 25.4 / 2048;
   Writeln(C1);
   Writeln(C2);
end.

FPC 3.2 (current trunk) returns different results for C1 and C2:

 6.423600000000000000E+00
 6.526400000000000000E+00

Delphi XE2 returns equal results for C1 and C2:

 6.52640000000000E+0000
 6.52640000000000E+0000

Is this a known bug?

(Btw. I tested on win32.)

Ondrej

Reply by email

Ondrej Pokorny
to Ondrej Pokorny

More info: if I use an Integer variable or even an Integer constant the results are correct:

program Project1;
var
   C0, C1, C2, C3, C4: Currency;
   D0: Double;
   I0: Integer;
begin
   I0 := 4736;
   C0 := I0;
   D0 := C0;
   C1 := C0 * 8 / 72 * 25.4 / 2048;
   C2 := D0 * 8 / 72 * 25.4 / 2048;
   C3 := I0 * 8 / 72 * 25.4 / 2048;
   C4 := 4736 * 8 / 72 * 25.4 / 2048;
   Writeln(C1);
   Writeln(C2);
   Writeln(C3);
   Writeln(C4);
   Readln;
end.

The wrong result comes only if a Currency variable is involved in the computation.

Ondrej

Reply by email