From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Simple Real_Time.Time_Span question
Date: 1998/10/13
Date: 1998-10-13T00:00:00+00:00 [thread overview]
Message-ID: <F0s4vI.DnC.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 6vvsgo$rvo$1@nnrp1.dejanews.com
dennison@telepath.com wrote:
: I need to convert values of Ada.Real_Time.Time_Span into floating point
: values for use in time-based simulation calculations. I'd think there *has*
: to be a way to do this, but I don't see one. All I see is the ability to do
: it indirectly via a conversion to Duration. But that looses the extra
: accuracy of Time_Span, which was the whole point of using it in the first
: place.
: Am I missing something?
You might try using Split(Time_Of(),...), and then multiplying the
resulting reduced Time_Span by 1000 before converting it to Duration.
That should end up preserving more of the accuracy.
You could run the 1000*<reduced Time_Span> back through the
Split(Time_Of()) combo again to get even more accuracy.
E.g.:
function To_Float(TS : Time_Span) return Float is
SC1, SC2, SC3 : Seconds_Count;
TS1, TS2, TS3 : Time_Span;
begin
-- Use Split(Time_Of()) to split time span into seconds and fraction
-- Repeat twice to get microseconds and fraction thereof
Split(Time_Of(0, TS), SC1, TS1);
Split(Time_Of(0, TS1*1000), SC2, TS2);
Split(Time_Of(0, TS2*1000), SC3, TS3);
-- NOTE: it is safe to multiply by 1000 because RM95 D.8(31)
-- guarantees that Time_Span'Last is >= 3600 seconds.
-- Finally do the conversion of the remaining time-span to duration
-- and add to other pieces.
return (Float(SC1)*1.0E9 + Float(SC2)*1.0E6 + Float(SC3)*1.0E3
+ Float(To_Duration(TS3*1000))) / 1.0E9;
end To_Float;
No comment on how fast the above will run...
: --
: T.E.D.
--
-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Burlington, MA USA
An AverStar Company
next prev parent reply other threads:[~1998-10-13 0:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-13 0:00 Simple Real_Time.Time_Span question dennison
1998-10-13 0:00 ` Tucker Taft [this message]
1998-10-13 0:00 ` dennison
1998-10-13 0:00 ` David C. Hoos, Sr.
1998-10-13 0:00 ` dennison
1998-10-14 0:00 ` Niklas Holsti
1998-10-14 0:00 ` Niklas Holsti
1998-10-14 0:00 ` Robert I. Eachus
1998-10-14 0:00 ` Jonathan Guthrie
1998-10-15 0:00 ` dennison
1998-10-16 0:00 ` Tucker Taft
1998-10-16 0:00 ` dennison
1998-10-16 0:00 ` dewar
1998-10-17 0:00 ` Niklas Holsti
1998-10-14 0:00 ` Keith Thompson
1998-10-14 0:00 ` dewar
1998-10-14 0:00 ` dennison
1998-10-14 0:00 ` Robert I. Eachus
1998-10-15 0:00 ` dennison
1998-10-16 0:00 ` Robert I. Eachus
1998-10-14 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox