comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: How to byte swap an IEEE Float?
Date: Fri, 01 Jul 2005 05:51:22 +0100
Date: 2005-07-01T05:51:22+01:00	[thread overview]
Message-ID: <m2acl7yvqt.fsf@grendel.local> (raw)
In-Reply-To: mailman.115.1120092778.17633.comp.lang.ada@ada-france.org

Stephen Leake <stephen_leake@acm.org> 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



  reply	other threads:[~2005-07-01  4:51 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
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 [this message]
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