Board index » delphi » (FPU) EXTENDED type read by C program

(FPU) EXTENDED type read by C program

I have a problem when reading a bynary file written by a program written
with delphi pascal and in compiled in Borldand platform.
I am using MS visual C++ but when I attempt to read extended types
(floating point numbers) (10 bytes) into long double this operation goes
wrong.

Please, Any idea? Any suggestion? Could it be a problem related to IEEE
754 floating points.

 

Re:(FPU) EXTENDED type read by C program


In article <393CEC0E.DDC8D...@mail.cilea.it>, Pietro Cerveri

Quote
<cerv...@mail.cilea.it> wrote:
> I have a problem when reading a bynary file written by a program written
> with delphi pascal and in compiled in Borldand platform.
> I am using MS visual C++ but when I attempt to read extended types
> (floating point numbers) (10 bytes) into long double this operation goes
> wrong.

The problem is most likely that most C compilers store the extended
type in 12 bytes (GCC does so anyway). Try writing the extended values
using something like

type
  extrec = record
    value: extended;
    dummy: word;
  end;

var
  f: file of extrec;
  e: extrec;

begin
   ...
   e.value := 1.0:
   e.dummy := 0;
   write(f,extrec);
   ...
end.

Since extended is not an official IEEE format (like you said), it's
possible that Visual C has a special type (like TP) that maps to
extended, otherwise it's probably a "long double".

Jonas

Re:(FPU) EXTENDED type read by C program


MSVC++ doesn't support the 10-byte real format any longer ('long double'
gives the same precision as 'double'). What you can do is:

    1. read the 'long double' into a 10-byte buffer.
    2. use a short ASM code snippet to convert it to a 'double'.

You lose some precision, but this is the best that can be done in MSVC.

The ASM snippet follows:

void ldbl2dbl(const void *ldbl, double *dbl)
{
    __asm   mov     eax,ldbl
    __asm   fld     tbyte ptr [eax]
    __asm   mov     eax,dbl
    __asm   fstp    qword ptr [eax]

Quote
}

Daniel Pfeffer

Quote
"Pietro Cerveri" <cerv...@mail.cilea.it> wrote in message

news:393CEC0E.DDC8DE23@mail.cilea.it...
Quote
> I have a problem when reading a bynary file written by a program written
> with delphi pascal and in compiled in Borldand platform.
> I am using MS visual C++ but when I attempt to read extended types
> (floating point numbers) (10 bytes) into long double this operation goes
> wrong.

> Please, Any idea? Any suggestion? Could it be a problem related to IEEE
> 754 floating points.

Other Threads