From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Fixed point constants issue
Date: Fri, 24 Sep 2010 14:38:11 -0700
Date: 2010-09-24T14:38:11-07:00 [thread overview]
Message-ID: <i7j6gn$amc$1@tornado.tornevall.net> (raw)
In-Reply-To: <i7idee$8ag$1@speranza.aioe.org>
On 09/24/2010 07:43 AM, Markus Schöpflin wrote:
>
> Are you sure about that? Because I compiled and ran the following
> program with an Ada 83 compiler (DEC Ada) and I got a different result.
> Note that I modified the delta to 0.5 to avoid any issues resulting from
> delta /= small.
>
> ---%<---
> with TEXT_IO; use TEXT_IO;
>
> procedure FIXED_POINT
> is
> type ALTITUDE is delta 0.5 range 0.0 .. 50_000.0;
>
> package ALTITUDE_IO is new FIXED_IO (ALTITUDE);
>
> FEET_PER_METER : constant := 0.3048;
> HEIGHT : constant := 10; -- Feet
>
> TEN_FEET_1 : constant := HEIGHT * FEET_PER_METER;
> TEN_FEET_2 : constant ALTITUDE := HEIGHT * FEET_PER_METER;
> begin
> ALTITUDE_IO.PUT (TEN_FEET_1); NEW_LINE; -- gives 3.0
> ALTITUDE_IO.PUT (TEN_FEET_2); NEW_LINE; -- gives 5.0 (*)
> end FIXED_POINT;
> --->%---
>
> (*) This certainly looks like FEET_PER_METER is converted to ALTITUDE
> before doing the multiplication.
That is interesting. I learned Ada 83 in 1984; I was explicitly taught that
static universal (sub)expressions were evaluated exactly by the compiler, using
universal operations. For example, I was taught that in
Pi : constant := 3.14159;
X : Float;
...
Reduce : loop
exit Reduce when X < Pi / 2;
X := X - Pi / 2;
end loop Reduce;
both occurrences of "Pi / 2" would be evaluated exactly by the compiler. Perhaps
I was taught wrong.
--
Jeff Carter
"We use a large, vibrating egg."
Annie Hall
44
next prev parent reply other threads:[~2010-09-24 21:38 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
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 [this message]
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