Sorry, I discovered a serious bug. The two smallest subnormal numbers (of 12 bytes LongReal type) cannot be written ; the program hangs and can't be stopped with CTRL+C. :-(
(gpc version 20010331, based on 2.95.2 19991024 (release) Machine : Intel Pentium 120 + Windows 98)
The first program allows to understand what is happening. The second one is the shorter I can write.
-- «Couperin»
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Program LRBug1;
{ ---------------------------------------------------------------------- BUG ! Intel IEEE Double-Extended (12 bytes) real numbers : The two smallest subnormal numbers cannot be written to the screen... The program hangs after : 1.000000000000001e-4950 (three steps above 0) ---------------------------------------------------------------------- } Const LongRealSize = 12; Type T_LongRealBis = Packed Array [1..LongRealSize] Of Byte; String2 = String(2); Var A : LongReal; Abis : T_LongRealBis Absolute A; {to read the binary content of A} I,N : Byte;
Function Byte2Hex(X : Byte): String2; Const Hexa : Array [0..15] Of Char = '0123456789ABCDEF'; Begin Byte2Hex := Hexa[X Shr 4] + Hexa[X And 15] End;
Begin If LongRealSize <> SizeOf(LongReal) Then Begin Writeln('This LongReal format (',SizeOf(LongReal), ') is unknown to this program.'); End Else Begin A := 3.3621031431120935120e-4932; {biggest subnormal number} For I := 0 To 64 Do Begin Write('16#'); {$ifdef __BYTES_BIG_ENDIAN__} For N := 1 To LongRealSize Do Write(Byte2Hex(Abis[N])); {$else} For N := LongRealSize DownTo 1 Do Write(Byte2Hex(Abis[N])); {$endif} Writeln(' is the representation of ',A); Writeln; A := A/2; End; Writeln; Writeln('OK') End End.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Program LRBug2;
Var A : LongReal; I : Byte;
Begin A := 3.3621031431120935120e-4932; {biggest subnormal number} For I := 0 To 64 Do Begin Writeln(A); End; Writeln('OK') End.
I wrote :
Program LRBug2;
Var A : LongReal; I : Byte;
Begin A := 3.3621031431120935120e-4932; {biggest subnormal number} For I := 0 To 64 Do Begin Writeln(A); End; Writeln('OK') End.
Aaaaargh ! Of course, it is :
Program LRBug2;
Var A : LongReal; I : Byte;
Begin A := 3.3621031431120935120e-4932; {biggest subnormal number} For I := 0 To 64 Do Begin Writeln(A); A := A/2; End; Writeln('OK') End.
-- «Couperin»
f.couperin wrote:
Sorry, I discovered a serious bug. The two smallest subnormal numbers (of 12 bytes LongReal type) cannot be written ; the program hangs and can't be stopped with CTRL+C. :-(
Well, the latter is certainly a bug^Wfeature of the OS (-; the program doesn't block or ignore any signals, so it should be stopped with CTRL-C, but Dos has always had problems with this ...).
The former is a GPC bug. I'm fixing it (will be uploaded soon, version 20010409).
Frank
PS:
{$ifdef __BYTES_BIG_ENDIAN__} For N := 1 To LongRealSize Do Write(Byte2Hex(Abis[N])); {$else} For N := LongRealSize DownTo 1 Do Write(Byte2Hex(Abis[N])); {$endif}
Is the floating point representation really dependent on the (integer) endianness -- at least for IEEE floats (I'm not sure). Anyone knows?