Broken frac function
Original Reporter info from Mantis: Wolfgang Ehrhardt
-
Reporter name:
Original Reporter info from Mantis: Wolfgang Ehrhardt
- Reporter name:
Description:
The frac function (https://www.freepascal.org/docs-html/rtl/system/frac.html) frac(d: ValReal):ValReal; is broken for large d values, e.g. for d:=1e20, and crashes with Runtime error 207.
Steps to reproduce:
Compile and run this 64-bit program on Win 64
program tfrac;
var
x,y: double;
begin
x := 1e20;
writeln('x=',x);
y := frac(x);
writeln('frac(x)=',y);
end.
Additional information:
This bug does not occur with the 32-bit version of the compiler.
Here is a log of a session.
------------------------------------------
D:\Work\DAMath>type tfrac.pas
program tfrac;
var
x,y: double;
begin
x := 1e20;
writeln('x=',x);
y := frac(x);
writeln('frac(x)=',y);
end.
D:\Work\DAMath>call fpc311 tfrac.pas
D:\Work\DAMath>D:\FPC311\bin\i386-win32\fpc.exe tfrac.pas
Free Pascal Compiler version 3.1.1-r20:38296 [2018/02/21] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling tfrac.pas
Linking tfrac.exe
9 lines compiled, 0.0 sec, 35952 bytes code, 2500 bytes data
D:\Work\DAMath>tfrac
x= 1.0000000000000000E+020
frac(x)= 0.0000000000000000E+000
D:\Work\DAMath>call fpc64311 tfrac.pas
D:\Work\DAMath>D:\FPC311\bin\i386-win32\ppcrossx64.exe tfrac.pas
Free Pascal Compiler version 3.1.1-r20:38794 [2018/04/22] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling tfrac.pas
Linking tfrac.exe
9 lines compiled, 0.1 sec, 37472 bytes code, 2036 bytes data
D:\Work\DAMath>tfrac
x= 1.0000000000000000E+020
Runtime error 207 at $0000000100001BD0
$0000000100001BD0
$0000000100001614
$0000000100001696
$00000001000095D0
$0000000100001580
$00000000773D59CD
$000000007763383D
Mantis conversion info:
- Mantis ID: 33635
- OS: windows 7/64
- OS Build: windows 7/64
- Build: 3.1.1-r20:38794 [2018/04/22]
- Platform: x86_64
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 38856 (#e3ea46d1),38903 (#abd893ca)
- Monitored by: » @CuriousKit (J. Gareth Moreton)
- Target version: 3.1.1