From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8200c5d9633351c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news9-e.free.fr!not-for-mail Date: Wed, 29 Jun 2005 22:10:57 +0200 From: Damien User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.7.2) Gecko/20040804 X-Accept-Language: fr, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to byte swap an IEEE Float? References: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> In-Reply-To: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <42c30054$0$27313$626a14ce@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 29 Jun 2005 22:11:00 MEST NNTP-Posting-Host: 82.235.135.166 X-Trace: 1120075860 news9-e.free.fr 27313 82.235.135.166:32792 X-Complaints-To: abuse@proxad.net Xref: g2news1.google.com comp.lang.ada:11738 Date: 2005-06-29T22:11:00+02:00 List-Id: Bj�rn a �crit : > 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? > I had to deal with byte swapping for floats and doubles between Intel and PPC. This was C++ and I discovered that swapping had to be done in a neutral form (byte array) before interpretation to float or double. Initialy I directly swapped floats and doubles, and for certain values some bits were changed. So a function with such a signature should never be defined: function Swap (X : Float) return Float; It seems that all bit patterns can not be legal floats. I interpreted this as a normalisation of the float, but this is not sure at all. So, to swap a float or a double X, do this : 1) convert X to a byte array Y (right size) 2) swap Y from host 1 format to network or archive format 3) send Y 4) read Y 5) swap Y from network or archive format to host 2 format 6) convert Y to X I don't know if this is related to your problem, but it seems similar, and it may help. It was C++, but those issues are language independent. Damien Carbonne