comp.lang.ada
 help / color / mirror / Atom feed
From: Larry Coon <lmcoon@home.com>
Subject: Arithmetic with durations
Date: 1997/09/08
Date: 1997-09-08T00:00:00+00:00	[thread overview]
Message-ID: <34149060.2E21@home.com> (raw)


I'm still on the learning curve with Ada, and I
can't figure out the problem with this code, or
the meaning of the diagnostic message I get.

This program is a contrived example that I
excerpted from a larger program I'm working on.
The idea is to use a short simulation time to
simulate a series of events in real time.  In
this case, the real time is 1000 seconds, with
events occuring every 25 seconds.  The simulation
is to run in 100 seconds, so the simulation
events are to occur every 25 * (100/1000) = 2.5
seconds.  All that this example program does is
display the current real and simulation times at
each event.

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."  Being pretty new at
Ada, I've never encountered "universal_fixed" and
don't understand what I'm doing wrong or what I
need to do to fix it.  I'd appreciate any insight
from those of you with more experience than me.
Here's the example program:

with ada.text_io; use ada.text_io;
procedure main is
  total_real_time: constant duration := 1000.0;
  total_sim_time: constant duration := 100.0;
  real_delay_time: constant duration := 25.0;
  sim_delay_time: duration;
  elapsed_real_time: duration := 0.0;
  elapsed_sim_time: duration := 0.0;
  package duration_io is new fixed_io(duration);
  use duration_io;
begin
  -- Convert the delay from real time to simulation time
  -- by multiplying it by the ratio of total simulation
  -- time to total real time.  Here is where it gives the
  -- error.
  sim_delay_time := real_delay_time * total_sim_time / total_real_time;

  loop
    delay sim_delay_time;
    elapsed_real_time := elapsed_real_time + real_delay_time;
    elapsed_sim_time := elapsed_sim_time + sim_delay_time;
    put(elapsed_real_time);
    put(elapsed_sim_time);
    new_line;
    exit when elapsed_sim_time >= total_real_time;
  end loop;
end main;

 
Larry Coon
University of California
larry@fs2.assist.uci.edu
and lmcoom@home.com




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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-08  0:00 Larry Coon [this message]
1997-09-09  0:00 ` Arithmetic with durations Simon Wright
1997-09-10  0:00 ` Jerry van Dijk
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