Sign in Join

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

Mailing lists / fpc-devel / 2021-07

Different computation precision in 32-bit and 64-bit app

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

NetSpirit

This code gives distinct results when compiled for Win32 and Win64
- Win32: 49744125
- Win64: 49744124.9999999

procedure Test;
var
  D: Double;
begin
  D := 3 * (exp(3 * ln(255)));
  WriteLn('Result: ' + FloatToStr(D));
end;

Somewhere is precision loss (or extra rounding). Is this good?

Reply by email

Sven Barth
to NetSpirit

NetSpirit via fpc-devel schrieb am Fr.,
30. Juli 2021, 15:37:

Show quoted text 15 lines
This code gives distinct results when compiled for Win32 and Win64 - Win32: 49744125 - Win64: 49744124.9999999 procedure Test; var D: Double; begin D := 3 * (exp(3 * ln(255))); WriteLn('Result: ' + FloatToStr(D)); end; Somewhere is precision loss (or extra rounding). Is this good?

On Win64 (and any non-x86 system) the intermediary results are calculated with Double precision while on any other x86 target it's calculated with Extended precision before being converted to Double for the assignment to D. So yes, that is as expected.

Regards,
Sven

Reply by email