(FPU) EXTENDED type read by C program 
Author Message
 (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.



Wed, 18 Jun 1902 08:00:00 GMT  
 (FPU) EXTENDED type read by C program

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.

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



Wed, 18 Jun 1902 08:00:00 GMT  
 (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:
> 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.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pascal Extended Type

2. Pascal 10 byte extended data type?

3. Pascal Extended Type

4. How do I read extended scan codes?

5. Reading typed files

6. Reading database-type files

7. Reading Blockwritten typed files using C

8. Reading Blockwritten typed files using C

9. Need to read type 0 PCX file in TP30

10. Read lots of records at the same time from a typed file

11. Reading Enumerated Types

12. Reading Diff. Var types

 

 
Powered by phpBB® Forum Software