|
From: Björn on 28 Jun 2005 09:53 I need to read some float values from file that have been written in big-endian byte order from a c-program. The simple swapping procedure that I have just interchanges the byte order of type IEEE_Float_32 to get little-endian. The problem is that for some values (eg. 33.229000) it is a "NaN" when doing IEEE_Float_32'Read and I get a constraint error (invalid data) from stream_io when the value is read. How do I get around this? Thanks Björn
From: Marius Amado Alves on 28 Jun 2005 11:06 On 28 Jun 2005, at 14:53, Björn wrote: > I need to read some float values from file that have been written in > big-endian byte order from a c-program. The simple swapping procedure > that I have just interchanges the byte order of type IEEE_Float_32 to > get little-endian. The problem is that for some values (eg. 33.229000) > it is a "NaN" when doing IEEE_Float_32'Read and I get a constraint > error (invalid data) from stream_io when the value is read. How do I > get around this? Simple. Setup an array of bytes with the same representation of the float type (use representation clauses and pragma Pack). Read the array of bytes. Swap the bytes. Convert to the float type (use unchecked conversion).
From: Simon Wright on 28 Jun 2005 11:55 Marius Amado Alves <amado.alves(a)netcabo.pt> writes: > On 28 Jun 2005, at 14:53, Bjýrn wrote: > >> I need to read some float values from file that have been written in >> big-endian byte order from a c-program. The simple swapping procedure >> that I have just interchanges the byte order of type IEEE_Float_32 to >> get little-endian. The problem is that for some values (eg. 33.229000) >> it is a "NaN" when doing IEEE_Float_32'Read and I get a constraint >> error (invalid data) from stream_io when the value is read. How do I >> get around this? > > Simple. Setup an array of bytes with the same representation of the > float type (use representation clauses and pragma Pack). Read the > array of bytes. Swap the bytes. Convert to the float type (use > unchecked conversion). Marius, I think you mean 'of the same length as the float type'? OP doesn't say what processor he gets the BE value from, but assuming PowerPC you either get Float (4 bytes) for digits <= 6 or Long_Float (8 bytes) for digits 7 .. 15. On Intel hardware there's an 80-bit Long_Long_Float (digits 18). -S
From: Martin Dowie on 28 Jun 2005 12:05 Bjýrn wrote: > I need to read some float values from file that have been written in > big-endian byte order from a c-program. The simple swapping procedure > that I have just interchanges the byte order of type IEEE_Float_32 to > get little-endian. The problem is that for some values (eg. 33.229000) > it is a "NaN" when doing IEEE_Float_32'Read and I get a constraint > error (invalid data) from stream_io when the value is read. How do I > get around this? What's the source/target for the values? PowerPC/ARM/Intelx86/Alpha/etc??
From: Marius Amado Alves on 28 Jun 2005 12:59
On 28 Jun 2005, at 16:55, Simon Wright wrote: > Marius Amado Alves <amado.alves(a)netcabo.pt> writes: > >> On 28 Jun 2005, at 14:53, Björn wrote: >> >>> I need to read some float values from file that have been written in >>> big-endian byte order from a c-program. The simple swapping procedure >>> that I have just interchanges the byte order of type IEEE_Float_32 to >>> get little-endian. The problem is that for some values (eg. >>> 33.229000) >>> it is a "NaN" when doing IEEE_Float_32'Read and I get a constraint >>> error (invalid data) from stream_io when the value is read. How do I >>> get around this? >> >> Simple. Setup an array of bytes with the same representation of the >> float type (use representation clauses and pragma Pack). Read the >> array of bytes. Swap the bytes. Convert to the float type (use >> unchecked conversion). > > Marius, > > I think you mean 'of the same length as the float type'? > > OP doesn't say what processor he gets the BE value from, but assuming > PowerPC you either get Float (4 bytes) for digits <= 6 or Long_Float > (8 bytes) for digits 7 .. 15. > > On Intel hardware there's an 80-bit Long_Long_Float (digits 18). Sure. You know, I meant representation = bits and bytes, implying same length. It seems the OP already has the float type (IEEE_Float_32), 32-bit = 4-byte long, and the data are floats of this length, only different in byte order. OP, if the data are of a different length, then you have to unchecked convert first to a float type of that length, and then normal convert to the final type (risking Constraint_Error). |