comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: How to byte swap an IEEE Float?
Date: Tue, 28 Jun 2005 16:55:07 +0100
Date: 2005-06-28T16:55:07+01:00	[thread overview]
Message-ID: <m2ekamzdb8.fsf@grendel.local> (raw)
In-Reply-To: mailman.102.1119971404.17633.comp.lang.ada@ada-france.org

Marius Amado Alves <amado.alves@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



  reply	other threads:[~2005-06-28 15:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-28 13:53 How to byte swap an IEEE Float? Björn
2005-06-28 15:06 ` Marius Amado Alves
2005-06-28 15:55   ` Simon Wright [this message]
2005-06-28 16:59     ` Marius Amado Alves
2005-06-28 20:43       ` Björn
2005-06-29  0:13         ` Marius Amado Alves
2005-06-30 19:14         ` Randy Brukardt
2005-06-28 16:05 ` Martin Dowie
2005-06-28 23:35 ` Stephen Leake
2005-06-29 10:00   ` Björn
2005-06-30  0:52     ` Stephen Leake
2005-07-01  4:51       ` Simon Wright
2005-06-29 20:10 ` Damien
2005-06-30 11:35   ` Peter Hermann
2005-06-30 22:26     ` Damien
2005-07-01  7:37       ` Peter Hermann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox