From: Simon Wright <simon@pogner.demon.co.uk>
Subject: Re: Arithmetic with durations
Date: 1997/09/09
Date: 1997-09-09T00:00:00+00:00 [thread overview]
Message-ID: <x7vd8miw8rs.fsf@pogner.demon.co.uk> (raw)
In-Reply-To: 34149060.2E21@home.com
Larry Coon <lmcoon@home.com> 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
next prev parent reply other threads:[~1997-09-09 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 [this message]
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