comp.lang.ada
 help / color / mirror / Atom feed
From: swhalen@netcom.com
Subject: Re: Assignment of small Float values
Date: 2000/04/29
Date: 2000-04-29T00:00:00+00:00	[thread overview]
Message-ID: <8efj12$87e$1@slb2.atl.mindspring.net> (raw)
In-Reply-To: 8dfm0q$8nr$1@nnrp1.deja.com

David W. Glessner <david_glessner@my-deja.com> wrote:
: Why does GNAT treat the non-zero constant as 0.0 in the assignment to
: F1 in the following example?  32-bit IEEE floating-point should
: support values down to around 10**-38 (and even down to 10**-45 or
: so for subnormal numbers).

: Note that Rational Apex Ada behaves as I expected.

: Is there something in Ada that allows the assignment of 0.0 or is
: this a GNAT bug?


: -- Test program that shows unexplained (to me at least) GNAT behavior
: for
: -- floating point assignments.
: --
: -- GNAT 3.12p Win98 displays:
: -- 0.00000E+00                           <-- Why does GNAT display 0.0?
: -- 6.66666666666667E-33
: -- 6.66667E-33
: --
: -- Rational Apex 3.0.0b for Solaris (Sparc) displays:
: -- 6.66667E-33
: -- 6.66666666666667E-33
: -- 6.66667E-33
: with Ada.Text_Io;
: procedure Test_Float_Range is
:     C : constant := 6.6666666666666666E-33;
:     F1 : Float := C;
:     F2 : Long_Float := C;
:     F3 : Float := Float (F2);
:     use Ada.Text_Io;
: begin
:     Put_Line (Float'Image (F1));
:     Put_Line (Long_Float'Image (F2));
:     Put_Line (Float'Image (F3));
: end Test_Float_Range;

I get the same results from ObjectAda 7.1 WinNT that you got from
Rational. I get the same results from GNAT 3.12p WinNT as you got with
GNAT Win98 (which eliminates a few variables).

I'm no floating point expert (I used one once, but didn't like it and
went right back to integers <g>), so I'm not a good one to answer your
question. Hopefully other's will chime in.

I did notice 

   type Short_Float     is digits 6
     range -16#0.FFFF_FF#E+32 .. 16#0.FFFF_FF#E+32;
     --    -3.40282E+38 ..  3.40282E+38

   type Float           is digits 6
     range -16#0.FFFF_FF#E+32 .. 16#0.FFFF_FF#E+32;
     --    -3.40282E+38 ..  3.40282E+38

   type Long_Float      is digits 15
     range -16#0.FFFF_FFFF_FFFF_F8#E+256 .. 16#0.FFFF_FFFF_FFFF_F8#E+256;
     --    -1.79769313486232E+308 ..  1.79769313486232E+308

   ...

in GNAT's "Standard" package definitions. I couldn't find the
equivalent in ObjectAda to see what they did.

Given Dr. Dewar's level of expertise in both math and Ada compilers,
I'd be surprised if GNAT's definitions are wrong, but given the
complexity of an Ada95 compiler, I wouldn't be shocked if there was a
bug.

I find it interesting that the 0.0 result comes back for anything
"more" than E-32 given the above definitions, but I read the RM to say
that float literals are supposed to be of the highest precision
supported by the implementation. But remember, I stay away from
heavy duty floating point stuff, because I _know_ I don't know
what I'm doing <g>...

Steve

-- 
{===--------------------------------------------------------------===}
                Steve Whalen     swhalen@netcom.com
{===--------------------------------------------------------------===}




  reply	other threads:[~2000-04-29  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-17  0:00 Assignment of small Float values David W. Glessner
2000-04-29  0:00 ` swhalen [this message]
2000-04-30  0:00   ` Robert I. Eachus
2000-05-02  0:00 ` Disturbing float conversions jboulais
2000-05-02  0:00   ` JP Thornley
2000-05-11  0:00     ` jboulais
2000-05-13  0:00       ` JP Thornley
replies disabled

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