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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3f2ed3f93fdb688b X-Google-Attributes: gid103376,public From: swhalen@netcom.com Subject: Re: Assignment of small Float values Date: 2000/04/29 Message-ID: <8efj12$87e$1@slb2.atl.mindspring.net>#1/1 X-Deja-AN: 617291029 References: <8dfm0q$8nr$1@nnrp1.deja.com> Organization: ? User-Agent: tin/pre-1.4-19990517 ("Psychonaut") (UNIX) (SunOS/4.1.4 (sun4m)) Newsgroups: comp.lang.ada Date: 2000-04-29T00:00:00+00:00 List-Id: David W. Glessner 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 ), 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 ... Steve -- {===--------------------------------------------------------------===} Steve Whalen swhalen@netcom.com {===--------------------------------------------------------------===}