From: jboulais@my-deja.com
Subject: Disturbing float conversions...
Date: 2000/05/02
Date: 2000-05-02T00:00:00+00:00 [thread overview]
Message-ID: <8en7ij$kr7$1@nnrp1.deja.com> (raw)
In-Reply-To: 8dfm0q$8nr$1@nnrp1.deja.com
I'm seeing something similar, but perhaps a little more disturbing
(Gnat 3.11p and WinNT 4.0).
I've got the following types defined:
type Long_Float_Type is digits 8 range -32768.000 .. 32767.000 ;
subtype Angle_Type is Long_Float_Type range -180.00000 .. 179.99451 ;
I find that when I do a 'Image on the 'First and 'Last of Angle_Type, I
get -1.7999872E+02 and 1.7999872E+02 respectively.
If I convert to a long_float (Ada standard, not Long_Float_Type) I get
-1.80000000000000E+02 and 1.79994510000127E+02 respectively, which is
closer, but the 'Last is a little bigger than I defined it to.
If I instantiate Text_IO.Float_IO with Angle_Type, I get -204.7 and
204.7, which really blows me away.
In article <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;
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
--
-----------------
Jeffrey Boulais
Sent via Deja.com http://www.deja.com/
Before you buy.
next prev parent reply other threads:[~2000-05-02 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
2000-04-30 0:00 ` Robert I. Eachus
2000-05-02 0:00 ` jboulais [this message]
2000-05-02 0:00 ` Disturbing float conversions 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