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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,388fc53f584bd695,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!news.netcologne.de!newsfeed-fusi2.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Vinzent Hoefler" Newsgroups: comp.lang.ada Subject: Fixed point constants issue Date: Mon, 13 Sep 2010 19:27:30 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: individual.net ZUG2L/Sh3eOv2YICRAdpcQfZAGkrk6xZOrgJCtTleqC8f1qQR9 Cancel-Lock: sha1:n9bwAIFZGz3QobeKolSxDmK8fII= User-Agent: Opera Mail/10.62 (Win32) Xref: g2news1.google.com comp.lang.ada:14047 Date: 2010-09-13T19:27:30+02:00 List-Id: Is this a GNAT bug or am I just stupid? Suppose we have a fixed point type (with a rather large delta): -- 8< -- with Ada.Text_IO; use Ada.Text_IO; procedure Fixed_Point is FEET_PER_METER : constant := 0.3048; HEIGHT : constant := 10; -- Feet type Altitude is delta (2.0**15 / 50_000.0) range 0.0 .. 50_000.0; TEN_FEET_1 : constant := HEIGHT * FEET_PER_METER; TEN_FEET_2 : constant Altitude := HEIGHT * FEET_PER_METER; TEN_FEET_3 : constant Altitude := TEN_FEET_1; TEN_FEET_4 : constant Altitude := Altitude (HEIGHT * FEET_PER_METER); begin Put_Line ("10 feet ~" & Altitude'Image (TEN_FEET_1) & " m."); Put_Line ("10 feet ~" & Altitude'Image (TEN_FEET_2) & " m."); Put_Line ("10 feet ~" & Altitude'Image (TEN_FEET_3) & " m."); Put_Line ("10 feet ~" & Altitude'Image (TEN_FEET_4) & " m."); end Fixed_Point; -- 8< -- Now let's run the test: 10 feet ~ 3.0 m. 10 feet ~ 0.0 m. <--- *oops*!? 10 feet ~ 3.0 m. 10 feet ~ 3.0 m. I can see what's going on in case of TEN_FEET_2 ("FEET_PER_METER" equals zero after the obviously happening type conversion to Altitude), but I sure wouldn't expect such a behavior from an Ada compiler, especially not when TEN_FEET_4 gives the expected result again[1]. To add to the confusion, the target compiler actually even does it the "right" (or rather: expected) way; but after reading all the relevant paragraphs in the ARM again and again, I still do not know if GNAT does it wrong here, or if we just entered one of the few dark corners in the Ada language. Can anyone shed some light on this? This has driven us crazy for weeks now. Vinzent. [1] Of course, "Altitude'(HEIGHT * FEET_PER_METER)" yields "0.0" again. At least this is consistent with my understanding so far. -- There is no signature.