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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ca038f7e5f1aa1b9 X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: Arithmetic with durations Date: 1997/09/09 Message-ID: #1/1 X-Deja-AN: 271086828 References: <34149060.2E21@home.com> X-NNTP-Posting-Host: pogner.demon.co.uk [158.152.70.98] Organization: At Home Newsgroups: comp.lang.ada Date: 1997-09-09T00:00:00+00:00 List-Id: Larry Coon writes: > 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; [...] > -- 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; If you write sim_delay_time := real_delay_time * duration (total_sim_time / total_real_time); -- A or sim_delay_time := real_delay_time * duration'(total_sim_time / total_real_time); -- B you should do better (works fine here, 3.09 on Linux). The relevant section of the LRM appears to be 4.5.5(18) et seq: =========== (18) Multiplication and division between any two fixed point types are provided by the following two predefined operators: (19) function "*"(Left, Right : universal_fixed) return universal_fixed function "/"(Left, Right : universal_fixed) return universal_fixed Legality Rules (20) The above two fixed-fixed multiplying operators shall not be used in a context where the expected type for the result is itself universal_fixed -- the context has to identify some other numeric type to which the result is to be converted, either explicitly or implicitly. ============ The AARM says: ============ 20.a Discussion: The small of universal_fixed is infinitesimal; no loss of precision is permitted. However, fixed-fixed division is impractical to implement when an exact result is required, and multiplication will sometimes result in unanticipated overflows in such circumstances, so we require an explicit conversion to be inserted in expressions like A * B * C if A, B, and C are each of some fixed point type. ============ I'm far from an expert in this area, we don't deal much with numbers, but I think that my version (A) means "evaluate a universal_fixed result and convert it to duration" while (B) means "evaluate as a duration". I suspect that choosing appropriate intermediate fixed-point types is less than straightforward?? (I remember fun with fixed-point types in Coral 66, our compiler was almost guaranteed to return 0 unless you really understood what was happening) -- Simon Wright Work Email: simon.j.wright@gecm.com GEC-Marconi Radar & Defence Systems Voice: +44(0)1705-701778 Command & Information Systems Divsion FAX: +44(0)1705-701800