comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: Floating point representation-help
Date: Mon, 12 Aug 2002 08:08:13 -0500
Date: 2002-08-12T08:08:13-05:00	[thread overview]
Message-ID: <mailman.1029157742.20629.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 14763faf.0208120429.658b842d@posting.google.com


----- Original Message ----- 
From: "Ashwath" <vashwathus@yahoo.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Monday, August 12, 2002 7:29 AM
Subject: Floating point representation-help


> Have look at the following program 
> with TEXT_IO; 
> with UNCHECKED_CONVERSION; 
> procedure UNCHECK_DEMO is 
> package INT_IO is new TEXT_IO.INTEGER_IO(LONG_LONG_INTEGER); 
> function INT_TO_FLT is 
> new UNCHECKED_CONVERSION( 
> SOURCE => LONG_LONG_INTEGER, 
> TARGET => FLOAT); 
> INT : LONG_LONG_INTEGER; 
> FLT : FLOAT; 
> begin 
> INT:=2#11111111100000000000000000000000#; 
> FLT:=INT_TO_FLT(INT); 
> INT_IO.put(INT,0,2); 
> end; 
First, You have not specified which compiler and platform
you're using, and things of this nature may be both platform-
_and_ compoler-dependent.

Second, the above program does not compile with GNAT on
Linux, for several reasons, one of which is that the size of
Long_Long_Integer on that compiler and platform is not the
same as the size of Float on that compiler and platform.

The following program does compile, and shows that the value
of Flt is indeed infinity.

There is nothing that says that computing a value of inifinity with
IEEE Floating point  representation should raise an exception,
since +inf, -Inf, and NaN are all legal IEEE Floating values.

However, performing a computation with such a value as an
operand should raise an exception.

with Interfaces;
with Text_IO;
with Unchecked_Conversion;
procedure Uncheck_Demo is
   function Int_To_Flt is new Unchecked_Conversion
     (Source => Interfaces.Unsigned_32,
      Target => Float);
   Int : Interfaces.Unsigned_32;
   Flt : Float;
begin
   Int:=2#11111111100000000000000000000000#;
   Flt:=Int_To_Flt(Int);
   Text_IO.Put_Line (Float'Image (Flt));
end;

Furthermore, in my modified version of your program, there is still
something that may be compiler-, and/or platform-dependent --
i.e., the declaration of Flt as type Float.  There is no guarantee
that every compiler on every platform defines the type Float as
32-bit IEEE floating point.

The GNAT compiler does make types available that re 32- and 64-
bit IEEE floating point on platforms where the underlying hardware
supports it.





  reply	other threads:[~2002-08-12 13:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-12 12:29 Floating point representation-help Ashwath
2002-08-12 13:08 ` David C. Hoos [this message]
2002-08-12 23:43   ` Robert Dewar
replies disabled

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