{
For those who want to understand the structure of the double extended
format, here is a little program which may be helpful :
(I'll appreciate comments to improve it)
--
«Couperin»
}
Program Lr2Scr;
{ ----------------------------------------------------------------------
What is Intel IEEE Double-Extended format (12 bytes) ?
"Couperin" <f.couperin(a)online.fr>
---------------------------------------------------------------------- }
Const
LongRealSize = 12;
Type
T_LongRealBis = Packed Array [1..LongRealSize] Of Byte;
String2 = String(2);
String11 = String(11);
String16 = String(16);
String27 = String(27);
Int16 = Integer(16);
Word16 = Word(16);
Word64 = Word(64);
Var
A : LongReal;
Abis : T_LongRealBis Absolute A;
Function Byte2Hex(X : Byte): String2;
Const
Hexa : Array [0..15] Of Char = '0123456789ABCDEF';
Begin
Byte2Hex := Hexa[X Shr 4] + Hexa[X And 15]
End;
Function ExtractE(X : T_LongRealBis): Word16;
Var
E : Word16;
Begin
E := X[10] And 2#01111111;
ExtractE := (E Shl 8) + X[9]
End;
Function F2Hex(X : T_LongRealBis): String16;
Var
S : String16 = '';
I : Byte;
Begin
For I := 8 DownTo 2 Do S := S + Byte2Hex((X[I] Shl 1) + (X[I-1] Shr 7));
S := S + Byte2Hex(X[1] Shl 1);
F2Hex := S
End;
Function Exponent(X : T_LongRealBis): Int16;
Var
E : Word16;
Begin
E := ((X[10] And 2#01111111) Shl 8) + X[9];
If E = 0
Then Exponent := -16382
Else Exponent := E - 16383
End;
Function Int2String(X:Integer):String11;
Var
S:String11;
Begin
Str(X,S);
Int2String := S
End;
Function LR2HexFloat(X : T_LongRealBis): String27;
Var
S : String27 = '$';
Begin
If (Abis[10] And 2#10000000) > 0 {sign}
Then S := S + '-'
Else S := S + '+';
If (Abis[8] And 2#10000000) > 0 {explicit leading significand bit}
Then S := S + '1.'
Else S := S + '0.';
LR2HexFloat := S + F2Hex(X) + 'p' + Int2String(Exponent(X))
End;
Procedure DisplayA;
Var
N : Byte;
Begin
Writeln(A:28,' = ');
Writeln(LR2HexFloat(Abis),' ("Hex Float") = ');
For N := LongRealSize DownTo 1 Do Write(Byte2Hex(Abis[N]));
Writeln(' (internal representation)');
Write('s (sign) = ');
Writeln(Ord((Abis[10] And 2#10000000) > 0));
Write('e (biased exponent) = ',ExtractE(Abis));
Writeln(' (e - 16383 = ',ExtractE(Abis) - 16383,')');
Write('j (explicit leading significand bit) = ');
Writeln(Ord((Abis[8] And 2#10000000) > 0));
Write('f (fraction) = 16#',F2Hex(Abis));
Writeln
End;
Begin
Writeln('Size of the LongReal type (in Bytes) : ',SizeOf(LongReal));
If LongRealSize <> SizeOf(LongReal)
Then Writeln('Sorry, this LongReal format (Size : ',SizeOf(LongReal),
') is unknown to this program.')
Else
Begin
{$ifdef __BYTES_BIG_ENDIAN__} {Is this really useful ?}
Writeln('Big endian format.'#10#13,
'Sorry, this program is made for the little endian format.')
{$else}
Writeln('Little endian format');
Repeat
Writeln;
Writeln('Enter a real number (0 to Quit)');
Readln(A);
Writeln;
DisplayA;
Until A = 0
{$endif}
End
End.