Loss of floating-point precision in 64-bit FPC 2.4.0rc1 under Win64
Original Reporter info from Mantis: Sergey.Bochkanov
-
Reporter name: Sergey Bochkanov
Original Reporter info from Mantis: Sergey.Bochkanov
- Reporter name: Sergey Bochkanov
Description:
Imprecise floating point operations in 64-bit FPC 2.4.0rc1 under Windows.
Code below calculates 512 as 512=2^9=Exp(9*Ln(2)) using double precision floating point.
According to IEEE standard and relatively small number of operations involved (hence small error accumulated) it should calculate result with error about several ulps, 5.0E-14 in this case. If internal 80-bit representation is used, then result will be precise (after we convert it back to Double). But even standard 64-bit IEEE floating point should allow us to obtain error as small as 5.0E-14
Win64 version calculates it with much larger error, 1.0E-9.
CODE:
-------------------
program t;
uses Sysutils;
var
C: Double;
N: Integer;
begin
N:=9;
C:=Exp(Double(N)*Ln(Double(2)));
WriteLn(C);
WriteLn(C-512);
end.
-------------------
Win64 output
-------------------
5.12000000001037E+002
1.03705133369658E-009
-------------------
first line is value calculated, second line is error.
Mantis conversion info:
- Mantis ID: 15305
- Fixed in version: 2.4.2
- Fixed in revision: 15175 (#75b5b6c7)
- Monitored by: » Sergey.Bochkanov (Sergey Bochkanov)
- Target version: 2.4.2