TFloatHelper incorrect results
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
TFloatHelper gives incorrect results for Mantissa and Fraction.
(At least it's results differ from Delphi)
Steps to reproduce:
program fl;
{$apptype console}
{$ifdef fpc}
{$mode objfpc}
{$h+}
{$endif}
uses
SysUtils, Math;
const
Signs: Array[Boolean] of Char = ('+','-');
Test = 1.999755859375; //(8192-1)/4096
function DbgS(E: Extended): String; overload;
begin
Result := 'Sign: ' + Signs[E.Sign] +
', Mantissa: ' + IntToHex(E.Mantissa, SizeOf(E.Mantissa)*2) +
', Exp: ' + IntToHex(E.Exp, SizeOf(E.Exp)*2) +
', Frac: ' + IntToHex(E.Frac, SizeOf(E.Frac)*2);
end;
function DbgS(D: Double): String; overload;
begin
Result := 'Sign: ' + Signs[D.Sign] +
', Mantissa: ' + IntToHex(D.Mantissa, SizeOf(D.Mantissa)*2) +
', Exp: ' + IntToHex(D.Exp, SizeOf(D.Exp)*2) +
', Frac: ' + IntToHex(D.Frac, SizeOf(D.Frac)*2);
end;
function DbgS(S: Single): String; overload;
begin
Result := 'Sign: ' + Signs[S.Sign] +
', Mantissa: ' + IntToHex(S.Mantissa, SizeOf(S.Mantissa)*2) +
', Exp: ' + IntToHex(S.Exp, SizeOf(S.Exp)*2) +
', Frac: ' + IntToHex(S.Frac, SizeOf(S.Frac)*2);
end;
procedure TestBreakDown;
var
E: Extended;
S: Single;
D: Double;
begin
E := Test;
writeln('E = ',E:20:20,#32,DbgS(E));
D := Test;
writeln('D = ',D:20:20,#32,DbgS(D));
S := Test;
writeln('S = ',S:20:20,#32,DbgS(S));
end;
begin
TestBreakDown;
end.
Outputs:
fpc 3.1.1 r37573 32-bit
Mode ObjFpc and Mode Delphi
E = 1.99975585937500000000 Sign: +, Mantissa: 7FF8000000000000, Exp: 0000000000003FFF, Frac: FFF8000000000000
D = 1.99975585937500000000 Sign: +, Mantissa: 000FFF0000000000, Exp: 00000000000003FF, Frac: 001FFF0000000000
S = 1.99975585900000000000 Sign: +, Mantissa: 00000000007FF800, Exp: 000000000000007F, Frac: 00000000087FF800
Delphi 10.2 Version 25.0.26309.314 32-bit
E = 1.99975585937500000000 Sign: +, Mantissa: FFF8000000000000, Exp: 0000000000003FFF, Frac: FFF8000000000000
D = 1.99975585937500000000 Sign: +, Mantissa: 001FFF0000000000, Exp: 00000000000003FF, Frac: 000FFF0000000000
S = 1.99975585937500000000 Sign: +, Mantissa: 0000000000FFF800, Exp: 000000000000007F, Frac: 00000000007FF800
Additional information:
The test using Delphi was done by rvk in the dutch Delphi forum: http://www.nldelphi.com/showthread.php?42731-TExtendedHelper-BuildUp()
Mantis conversion info:
- Mantis ID: 32837
- OS: Windows
- OS Build: 10
- Build: r37573
- Platform: i386
- Fixed in version: 3.1.1
- Fixed in revision: 39346 (#a9205c9f)
- Target version: 3.2.0