SIGFPE with Val(FloatToStr(MaxDouble))
Original Reporter info from Mantis: zoran
-
Reporter name: Zoran Vučenović
Original Reporter info from Mantis: zoran
- Reporter name: Zoran Vučenović
Description:
Standard Pascal Val procedure raises SIGFPE.
As Val should never raise exception, but only return non-zero value in third parameter, this is even more annoying bug.
Steps to reproduce:
(tested on Windows 7, 32-bit):
program TestVal;
uses SysUtils, Math;
var
D: Double;
S: AnsiString;
E: Word;
begin
D := Math.MaxDouble;
WriteLn(D);
S := FloatToStr(D);
Writeln(S);
Val(S, D, E); // SIGFPE here!
WriteLn(D);
ReadLn;
end.
Additional information:
- the declaration of Math.MaxDouble is changed in FPC 3.2
in 3.0.4 it was:
MaxDouble = 1.7e+308;
And in 3.2 it is:
MaxDouble = 1.7976931348623157e+308;
Therefore the example I gave needs 3.2 to reproduce the bug.
- If you replace the line "S := FloatToStr(D);" with "Str(D, S);" or "WriteStr(S, D);", the bug dissapears!
The difference is only in + sign in front of the exponent:
FloatToStr returns "1.7976931348623157e308" (no + in front of the exponent)
Str(D, S) returns "1.7976931348623157e+308" (notice + in front of the exponent - e+308)
Then, Val gives SIGSEGV only when this "+" sign is not present in front of the exponent.
Mantis conversion info:
- Mantis ID: 37087
- Version: 3.2.0
- Fixed in version: 3.3.1