FloatToStr produces incorrect output for selected numbers.
Original Reporter info from Mantis: mftq75
-
Reporter name: C Western
Original Reporter info from Mantis: mftq75
- Reporter name: C Western
Description:
var
f: Extended;
begin
f := 999999999999990;
WriteLn(f, ' ', FloatToStr(f), ' ', f-StrToFloat(FloatToStr(f)));
end;
outputs:
9.9999999999999000E+0014 99999999999999 8.9999999999999100E+0014
I also noticed that FloatToStr produces < 15 figures of precision for numbers in the range 0.1 - 0.0001, so that 0.0000123456789123457 prints as 0.000012345678912.
The attached patch is is rewrite of part the FloatToStrFIntl to fix these problems. I have also added more tests for FloatToStr, which tests:
Abs(f-StrToFloat(FloatToStr(f))) < 6e-15 (or 6e-10 for single)
for a wide selection of input values. The old routine produces lots of failures.
My replacement routine also avoids multiple calls to the underlying conversion routine.
Mantis conversion info:
- Mantis ID: 16907
- OS: Linux
- Platform: i386
- Version: 2.5.1
- Fixed in version: 2.6.1
- Fixed in revision: 20427 (#75aac428)