Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-03

Converting TP Reals in ANSI-C

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Trevor Cooper

Many examples can be found to demonstrate how to convert the Turbo Pascal 6 byte Real into IEEE compliant floating point types WITHIN a PASCAL environment.

I need to write routines in ANSI C that can read/write these reals from/to a binary file when they are part of variant record type. I am concerned that I must also consider word/byte ordering as well as the internal representation of the exponent and mantissa.

Has anybody seen and/or does anybody have source code for doing this in ANSI C?

If not, can anybody enlighten me as to exactly how the following record should be written to a binary file, particularly the Reals?

Record_Type = (Header_Block, Data_Block);
Data_Record = record case Header_Trailer : Record_Type of Header_Block : ( {variant type 1}
NumChan : Integer; {16}
Gain : Integer; {0}
Freq : Real; {100.0}
SampT : Real; {10.0}
Ymin : array[0..15] of Real; {0.0}
Ymax : array[0..15] of Real; {4095.0}
Slope : array[0..15] of Real; {1.0}
Intercept : array[0..15] of Real; {0.0}

                     Data_time : LongInt;
                   );
                   Data_Block : ({variant type 2}
                    DataLine : array[0..4095] of Integer; {0-4095 or -9999}
                   );
               end; {record case}

Trevor Cooper
UCSD Division of Physiology

Reply by email

Ralf Quint
to Trevor Cooper
you wrote 11 lines
Many examples can be found to demonstrate how to convert the Turbo Pascal 6 byte Real into IEEE compliant floating point types WITHIN a PASCAL environment. I need to write routines in ANSI C that can read/write these reals from/to a binary file when they are part of variant record type. I am concerned that I must also consider word/byte ordering as well as the internal representation of the exponent and mantissa. Has anybody seen and/or does anybody have source code for doing this in ANSI C?

I have some code for this somewhere. Unfortunately, I'm in the process of moving right now and have already most of the my programming stuff which i don't currently need already packed up. I'll see that i send it to you as soon as I'm over with this mess...

Ralf

Reply by email