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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8200c5d9633351c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsgate.cistron.nl!newsfeed.stueberl.de!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: How to byte swap an IEEE Float? Date: Fri, 01 Jul 2005 05:51:22 +0100 Organization: Pushface Message-ID: References: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> <1120039226.101013.221510@g43g2000cwa.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1120193481 12225 62.49.19.209 (1 Jul 2005 04:51:21 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Fri, 1 Jul 2005 04:51:21 +0000 (UTC) Cancel-Lock: sha1:3YlE5rZUs/7/WbiusoGDmaVsyms= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:11798 Date: 2005-07-01T05:51:22+01:00 List-Id: Stephen Leake writes: > Ok. So you have some code that generates a NaN, sends it over a > network or something, and then some Ada code wants to store it in a > Float value, still as a NaN. I understood that the problem was read a big-endian value from a file into a little-endian float byte-swap the float Clearly you're at risk until the swap. Personally I'd read into an array 1 .. 4 of Unsigned_8, swap, unchecked convert to Float ... > Unchecked_Conversion should support that. I'm not quite clear what > will happen when you try to use the value or even assign the value; > you'll probably get Constraint_Error. You might try 'Valid. > The Ada model of floating point numbers does _not_ include NaN's, nor > infinities. You can generate them, but they are not 'Valid. With GNAT, you don't get a Constraint_Error if you use type Float, but you do if you use subtype Checking_Float is Float range Float'First .. Float'Last; -S