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 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.158.31.10.MISMATCH!newsfeed-0.progon.net!progon.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Vinzent Hoefler" Newsgroups: comp.lang.ada Subject: Re: Fixed point constants issue Date: Mon, 13 Sep 2010 20:25:43 +0200 Message-ID: References: <1f0l0baynq1x7$.phl9cqpwcr37.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: individual.net X4/8kX1Migb3G9C4nlHEnA5q6ObexvpWH7MroqWYX80XlvDDdi Cancel-Lock: sha1:ewmDf7usEexFQFdzWQMocMNm8t0= User-Agent: Opera Mail/10.62 (Win32) Xref: g2news1.google.com comp.lang.ada:14049 Date: 2010-09-13T20:25:43+02:00 List-Id: On Mon, 13 Sep 2010 20:04:32 +0200, Dmitry A. Kazakov wrote: > On Mon, 13 Sep 2010 19:27:30 +0200, Vinzent Hoefler wrote: > >> 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; > > [...] >> Can anyone shed some light on this? This has driven us crazy for weeks >> now. >> >> [1] Of course, "Altitude'(HEIGHT * FEET_PER_METER)" yields "0.0" again. >> At least this is consistent with my understanding so far. > > Hmm, what did you expect? 0.3048 (FEET_PER_METER) is 0 when Altitude. > That is because 2.0**15/50_000.0=0.65536 > 0.3048. Yes, of course. Still, it's not quite intuitive why TEN_FEET_1 : constant := HEIGHT * FEET_PER_METER; TEN_FEET_2 : constant Altitude := HEIGHT * FEET_PER_METER; just because a type is given in the second case. I would expect the compiler to evaluate the expression "HEIGHT * FEET_PER_METER" _before_ converting it to the appropriate fixed point type. And, obviously it does this that when evaluating TEN_FEET_4 : constant Altitude := Altitude (HEIGHT * FEET_PER_METER); In our opinion, this type conversion on the right hand side shouldn't be necessary, yet it is (with GNAT). Vinzent. -- There is no signature.