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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ca038f7e5f1aa1b9,start X-Google-Attributes: gid103376,public From: Larry Coon Subject: Arithmetic with durations Date: 1997/09/08 Message-ID: <34149060.2E21@home.com>#1/1 X-Deja-AN: 270828640 Organization: @Home Network Reply-To: lmcoon@home.com Newsgroups: comp.lang.ada Date: 1997-09-08T00:00:00+00:00 List-Id: 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