comp.lang.ada
 help / color / mirror / Atom feed
From: "Vinzent Hoefler" <nntp-2010-09@t-domaingrabbing.de>
Subject: Re: Fixed point constants issue
Date: Mon, 13 Sep 2010 22:35:42 +0200
Date: 2010-09-13T22:35:42+02:00	[thread overview]
Message-ID: <op.viznhs19d20q5n@jellix.jlfencey.com> (raw)
In-Reply-To: 8f7b0nF6hfU1@mid.individual.net

On Mon, 13 Sep 2010 21:05:58 +0200, Niklas Holsti  
<niklas.holsti@tidorum.invalid> 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.



  reply	other threads:[~2010-09-13 20:35 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13 17:27 Fixed point constants issue Vinzent Hoefler
2010-09-13 18:04 ` Dmitry A. Kazakov
2010-09-13 18:25   ` Vinzent Hoefler
2010-09-13 19:05     ` Niklas Holsti
2010-09-13 20:35       ` Vinzent Hoefler [this message]
2010-09-13 20:35       ` Jeffrey Carter
2010-09-13 21:06         ` Vinzent Hoefler
2010-09-14  5:39         ` Niklas Holsti
2010-09-24 14:43         ` Markus Schöpflin
2010-09-24 20:05           ` Vinzent Hoefler
2010-09-24 21:38           ` Jeffrey Carter
2010-09-24 22:42             ` Vinzent Hoefler
2010-09-25  0:16               ` Jeffrey Carter
2010-09-27 10:33                 ` Markus Schöpflin
2010-09-27 18:57                   ` Jeffrey Carter
2010-09-28  8:16                     ` Markus Schöpflin
2010-09-28 17:28                       ` Jeffrey Carter
2010-10-05  6:27                         ` Randy Brukardt
2010-10-05 18:40                           ` Jeffrey Carter
2010-09-27 17:58             ` Adam Beneschan
2010-09-13 20:32     ` Dmitry A. Kazakov
2010-09-13 21:08       ` Vinzent Hoefler
2010-09-14  6:54         ` J-P. Rosen
2010-09-14 18:28           ` Vinzent Hoefler
2010-09-14  7:47         ` Dmitry A. Kazakov
2010-09-14 17:42           ` Vinzent Hoefler
2010-09-15  8:35             ` Dmitry A. Kazakov
2010-09-15 17:24               ` Vinzent Hoefler
2010-09-15 20:11                 ` Dmitry A. Kazakov
2010-09-14 19:44   ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox