Board index » cppbuilder » Re: Reading a BCB streamed double in DotNet...

Re: Reading a BCB streamed double in DotNet...


2003-08-12 03:27:13 AM
cppbuilder87
Borland is writing 80 bit floating point or the so-called "long double".
++PLS
In article < XXXX@XXXXX.COM >,
XXXX@XXXXX.COM says...
Quote
I am trying to parse a DFM file in DotNet.
I have everything working except vaExtended (0x05) and vaDate (0x11) from
the TValueType enum.
It looks like Borland and DotNet use different double streaming formats.
Borland's seems to be 10 bytes (plus the 0x05 prefix), whereas DotNet's are
8 bytes.
The following two chunks of code should demonstrate my problem.


//DotNet C# code
FileStream fs = new FileStream("c:\\dotnet.bin",FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write((double)0);
bw.Write((double)1);
bw.Write((double)2);
bw.Write((double)3);
bw.Close();
fs.Close();

//DotNet C# output
00 00 00 00 00 00 00 00
00 00 00 00 00 00 F0 3F
00 00 00 00 00 00 00 40
00 00 00 00 00 00 08 40


//Borland C++ code
TFileStream *fs = new TFileStream("c:\\borland.bin",fmCreate);
TWriter *bw = new TWriter(fs,0x1000);
bw->WriteFloat(0);
bw->WriteFloat(1);
bw->WriteFloat(2);
bw->WriteFloat(3);
delete bw;
delete fs;

//Borland C++ output
05 00 00 00 00 00 00 00 00 00 00
05 00 00 00 00 00 00 00 80 FF 3F
05 00 00 00 00 00 00 00 80 00 40
05 00 00 00 00 00 00 00 C0 00 40


So I have two options. I can either translate Borland streamed double bytes
into DotNet streamed double bytes and then natively read them in DotNet, or
I can manually generate a double from the Borland streamed double bytes
using multiplications etc.

Is anybody able to assist me?

 
 

Re:Re: Reading a BCB streamed double in DotNet...

Quote
Borland is writing 80 bit floating point or the so-called "long
double".
Ok, that explains the length difference. Now how do I go about getting that
long double into dotnet (which doesn't support long doubles as far as I can
see)? I can guarentee that the long double will not fall outside the range
of a standard double.
Is there an algorithm to translate 10 long double bytes into 8 standard
double bytes?
Or is it easier just to do the arithmetic and figure out the floating point
number from the 10 bytes manually?