comp.lang.ada
 help / color / mirror / Atom feed
From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk)
Subject: Re: Arithmetic with durations
Date: 1997/09/10
Date: 1997-09-10T00:00:00+00:00	[thread overview]
Message-ID: <873869111.49snx@jvdsys.nextjk.stuyts.nl> (raw)
In-Reply-To: 34149060.2E21@home.com


In article <34149060.2E21@home.com> lmcoon@home.com writes:

>The line that calculates the amount of simulation
>time to wait for each event won't compile.  My
>compiler (Thomson ObjectAda running in Windows 95)
>produces the following diagnostic: "LRM:4.5.5(20)
>The fixed-fixed multiplying operators shall not be
>used in a context where the expected type for the
>result is universal_fixed."

Removing the fat, the problem becomes:

   procedure Main is

      Sim_Delay_Time : Duration;

      Real_Delay_Time: constant Duration :=   25.0;
      Total_Sim_Time : constant Duration :=  100.0;
      Total_Real_Time: constant Duration := 1000.0;

   begin
     Sim_Delay_Time := Real_Delay_Time * Total_Sim_Time / Total_Real_Time;
   end Main;

If you looked up 4.5.5 you will have found that the rule used for
the multiplication is given in 4.5.5 (19):

   function "*" (Left, Right : universal_fixed) return universal_fixed.

However, line (20) then makes the exception that this will only work
if the destination type is something other then universal_fixed, either
im- or explicit.

However, as the result of the multiplication will be used for a
division also defined in 4.5.5 (19) the resulting type _is_
implicitly an universal_fixed, so the multiplication is illegal.

To fix the problem, simply make the return type explicit, like:

   procedure Main is

      Sim_Delay_Time : Duration;

      Real_Delay_Time: constant Duration :=   25.0;
      Total_Sim_Time : constant Duration :=  100.0;
      Total_Real_Time: constant Duration := 1000.0;

   begin
     Sim_Delay_Time := Duration (Real_Delay_Time * Total_Sim_Time)
       / Total_Real_Time;
   end Main;

Now, perhaps one of our resident RM guru's can answer the really
interesting question: why this exception ?

--

-- Jerry van Dijk | Leiden, Holland
-- Consultant     | Team Ada
-- Ordina Finance | jdijk@acm.org




  parent reply	other threads:[~1997-09-10  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-08  0:00 Arithmetic with durations Larry Coon
1997-09-09  0:00 ` Simon Wright
1997-09-10  0:00 ` Jerry van Dijk [this message]
1997-09-10  0:00   ` Tucker Taft
1997-09-11  0:00     ` Robert Dewar
replies disabled

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