Wrong typecast to double in $mode delphi
Original Reporter info from Mantis: Wolfgang Ehrhardt
-
Reporter name:
Original Reporter info from Mantis: Wolfgang Ehrhardt
- Reporter name:
Description:
The following program
program ftc;
var
d: double;
begin
writeln(double(10));
end.
writes in Delphi/TP mode
4.9406564584124654E-323
instead of
1.0000000000000000E+001
Steps to reproduce:
Run the progra m for different compilers, here is my log
C:\TMP>fpc304 ftc.pas
C:\TMP>D:\FPC304\bin\i386-win32\fpc.exe ftc.pas
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling ftc.pas
Linking ftc.exe
3 lines compiled, 0.1 sec, 34480 bytes code, 2420 bytes data
C:\TMP>ftc.exe
1.0000000000000000E+001
C:\TMP>fpc304 -Sd ftc.pas
C:\TMP>D:\FPC304\bin\i386-win32\fpc.exe -Sd ftc.pas
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling ftc.pas
Linking ftc.exe
3 lines compiled, 0.1 sec, 34576 bytes code, 2436 bytes data
C:\TMP>ftc.exe
4.9406564584124654E-323
C:\TMP>fpc311 ftc.pas
C:\TMP>D:\FPC311\bin\i386-win32\fpc.exe ftc.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 ftc.pas
Linking ftc.exe
3 lines compiled, 0.1 sec, 35760 bytes code, 2500 bytes data
C:\TMP>ftc.exe
1.0000000000000000E+001
C:\TMP>fpc311 -Sd ftc.pas
C:\TMP>D:\FPC311\bin\i386-win32\fpc.exe -Sd ftc.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 ftc.pas
Linking ftc.exe
3 lines compiled, 0.1 sec, 35872 bytes code, 2500 bytes data
C:\TMP>ftc.exe
4.9406564584124654E-323
C:\TMP>fpc64304 ftc.pas
C:\TMP>D:\FPC304\bin\i386-win32\ppcrossx64.exe ftc.pas
Free Pascal Compiler version 3.0.4 [2017/10/06] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling ftc.pas
Linking ftc.exe
4 lines compiled, 0.1 sec, 37136 bytes code, 1828 bytes data
C:\TMP>ftc.exe
1.0000000000000000E+001
C:\TMP>fpc64304 -Sd ftc.pas
C:\TMP>D:\FPC304\bin\i386-win32\ppcrossx64.exe -Sd ftc.pas
Free Pascal Compiler version 3.0.4 [2017/10/06] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling ftc.pas
Linking ftc.exe
4 lines compiled, 0.1 sec, 37328 bytes code, 1860 bytes data
C:\TMP>ftc.exe
4.9406564584124654E-323
Additional information:
See also http://forum.lazarus.freepascal.org/index.php/topic,42078.msg293046
where it is confirmed the issue is also present on Lazarus 1.8.4 Linux.
It seems to be some 'hard' cast like absolute. The denormal number has the hex representation $000000000000000A = 4.9406564584124654E-323, and the $..0A is 10 as decimal. This also happens in TP mode. I will file an issue report after lunch.
The issue occurs for other compiler versions too.
Mantis conversion info:
- Mantis ID: 34068
- OS: Windows / Linux
- OS Build: Win7 / 64
- Platform: X86 / X86_64
- Version: 3.0.4