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,31d67020d4b04d5b X-Google-Attributes: gid103376,public From: dennison@telepath.com Subject: Re: Simple Real_Time.Time_Span question Date: 1998/10/13 Message-ID: <700dcn$f9s$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 400718186 References: <6vvsgo$rvo$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x4.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Tue Oct 13 20:32:23 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I) Date: 1998-10-13T00:00:00+00:00 List-Id: In article <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* Update: Here's what I ended up doing: -- Routine to convert a real_time time_span into a float. function To_Float ( Span : in Ada.Real_Time.Time_Span ) return Float is -- We have to convert to and from Time because its the only way to handle -- time spans of more than about 2 seconds or so without getting a constraint -- error. Span_Time : Ada.Real_Time.Time := Ada.Real_Time.Time_Of (SC => 0, TS => Span); Ticks : Integer; Subspan : Ada.Real_Time.Time_Span; Seconds : Ada.Real_Time.Seconds_Count; begin Ada.Real_Time.Split (T => Span_Time, SC => Seconds, TS => Subspan); Ticks := Subspan / Ada.Real_Time.Time_Span_Unit; return Float(Seconds) + Float(Ticks * Ada.Real_Time.Time_Unit); end To_Float; I don't much like this solution, as it will blow up in the unlikely event that there are more Time_Span_Units in a second than Integer'last. Plus it performs *way* more work than the following code that this vendor *could* have put in the body of Ada.Real_Time: function To_Float ( Span : in Ada.Real_Time.Time_Span ) return Float is begin return Float(Span.sec) + (Float(Span.msec) * Time_Unit); end; -- T.E.D. -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own