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!news4.google.com!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 22:35:42 +0200 Message-ID: References: <1f0l0baynq1x7$.phl9cqpwcr37.dlg@40tude.net> <8f7b0nF6hfU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: individual.net jZFr6W82pS4jtzIUwYRs0QX8fJtkb2le3YNt+8BgP7ZAczKnZI Cancel-Lock: sha1:+Jq5A4vxJkCTYN+M+N5tGVwPT/A= User-Agent: Opera Mail/10.62 (Win32) Xref: g2news1.google.com comp.lang.ada:14058 Date: 2010-09-13T22:35:42+02:00 List-Id: On Mon, 13 Sep 2010 21:05:58 +0200, Niklas Holsti wrote: > Vinzent Hoefler wrote: > > > I would expect the compiler to evaluate the expression > > "HEIGHT * FEET_PER_METER" [for TEN_FEET_2] _before_ > > converting it to the appropriate fixed point type. > > The declaration of TEN_FEET_2 is an object declaration with type > Altitude, therefore the right-hand-side expression is expected to be of > type Altitude and so the "*" will be resolved to the Altitude > multiplication operator "*" (Left, Right : Altitude) return Altitude, > with result zero. That's what I suspected. So, although the result is seriously wrong compared to the mathematical result of the given static expression, the compiler is still correct? :( > I agree that this is a bit nasty and counter-intuitive. Perhaps the > compiler should warn that the conversion of the universal_real number > 0.3048 to Altitude is seriously inexact, but then, what is "seriously"? Well, GNAT warns with a "static fixed-point value is not a multiple of Small", but this one is quite useless, because that warning is issued for virtually every expression in the example, so it's hard to identify the real problematic cases. >> And, obviously it does this that when evaluating >> TEN_FEET_4 : constant Altitude := Altitude (HEIGHT * FEET_PER_METER); > > Here the right-hand side expression is a type conversion, in fact a > value conversion, and so the operand HEIGHT * FEET_PER_METER is expected > to be of any numeric type. At first sight the multiplication could be > resolved to the root "*" or to the Altitude "*", which would thus be > ambiguous. However, RM 8.6(29) says that the ambiguity is resolved by > using the root "*", giving the more precise result. Right. That was the part of the ARM I didn't read. Obviously I was too focused on the fixed point arithmetic model in Annex G 2.3. So, it's the other compiler that does it wrong (according to my colleague, only GNAT gives the "wrong" results)? I may run a short test tomorrow to confirm that this is really the case. There isn't any paragraph in the ARM that would allow the compiler to arbitrarily choose any of both interpretations, is there? Vinzent. -- There is no signature.