comp.lang.ada
 help / color / mirror / Atom feed
* Time to float??
@ 2001-09-30 15:01 Michael Andersson
  2001-09-30 21:36 ` Des Walker
  2001-09-30 23:18 ` Robert Dewar
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Andersson @ 2001-09-30 15:01 UTC (permalink / raw)


Hi!
Could somebody please show me how to convert Ada.Real_time type Time to
a float so that for example 1.5 seconds is represented as the real
number 1.5.

Thanks!
/Michael Andersson



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Time to float??
  2001-09-30 15:01 Time to float?? Michael Andersson
@ 2001-09-30 21:36 ` Des Walker
  2001-09-30 21:56   ` Des Walker
  2001-09-30 23:18 ` Robert Dewar
  1 sibling, 1 reply; 5+ messages in thread
From: Des Walker @ 2001-09-30 21:36 UTC (permalink / raw)



Michael Andersson <a98mican@ida.his.se> wrote in message
news:3BB78935.33B5C91A@ida.his.se...
> Hi!
> Could somebody please show me how to convert Ada.Real_time type Time
to
> a float so that for example 1.5 seconds is represented as the real
> number 1.5.
>
> Thanks!
> /Michael Andersson

I wonder if what you want is to convert a Time_Span type rather than a
Time type value. A value of type Time is more likely to be a form of
'10:21pm, 30 September 2001', and a Time_Span type a form of 1.5
seconds. (Subtract two Ada.Real_Time.Time values and the function
provided in the Ada.Real _Time package provides an
Ada.Real_Time.Time_Span type value)

Ada.Real_Time provides the To_Duration function to convert an
Ada.Real_Time.Time_Span value to a Duration. You can cast this to a real
floating type, or you can use Duration'Image if you're printing the
result.

    Regards
    Des Walker






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Time to float??
  2001-09-30 21:36 ` Des Walker
@ 2001-09-30 21:56   ` Des Walker
  0 siblings, 0 replies; 5+ messages in thread
From: Des Walker @ 2001-09-30 21:56 UTC (permalink / raw)



Des Walker <des.walker@dessy.fsnet.co.uk> wrote in message
news:9p838f$2fl$1@newsg1.svr.pol.co.uk...
> A value of type Time is more likely to be a form of
> '10:21pm, 30 September 2001', and a Time_Span type a form of 1.5
> seconds.

Apologies, that statement is likely to be misleading, what I meant was
the Ada.Real_Time.Time type is similar to the Calendar.Time type in that
it can be used in instructions like 'delay until <time>;', whereas 1.5
seconds sounds more like a duration as you would use in 'delay 1.5';
(without the until clause).

    Regards
    Des Walker





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Time to float??
  2001-09-30 15:01 Time to float?? Michael Andersson
  2001-09-30 21:36 ` Des Walker
@ 2001-09-30 23:18 ` Robert Dewar
  2001-10-01 13:54   ` Ted Dennison
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Dewar @ 2001-09-30 23:18 UTC (permalink / raw)


Michael Andersson <a98mican@ida.his.se> wrote in message news:<3BB78935.33B5C91A@ida.his.se>...
> Hi!
> Could somebody please show me how to convert Ada.Real_time type Time to
> a float so that for example 1.5 seconds is represented as the real
> number 1.5.
> 
> Thanks!
> /Michael Andersson


This is not a meaningful conversion. the type Time 
represents a time, not a duration.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Time to float??
  2001-09-30 23:18 ` Robert Dewar
@ 2001-10-01 13:54   ` Ted Dennison
  0 siblings, 0 replies; 5+ messages in thread
From: Ted Dennison @ 2001-10-01 13:54 UTC (permalink / raw)


In article <5ee5b646.0109301518.2a49abc4@posting.google.com>, Robert Dewar
says...
>
>Michael Andersson <a98mican@ida.his.se> wrote in message news:<3BB78935.33B5C91A@ida.his.se>...
>> Could somebody please show me how to convert Ada.Real_time type Time to
>> a float so that for example 1.5 seconds is represented as the real
>> number 1.5.
>
>This is not a meaningful conversion. the type Time 
>represents a time, not a duration.

That's true. But *two* of them can be used for that purpose. I often find myself
doing this conversion in debugging code, so that I can make checkpoint outputs
of the result at various places.

There are two ways to do this; a thourough way and a quick-and-dirty way. Since
I ususally do this for debugging purpose, I ususaly pick the latter.

The way I have done this is to subtract Ada.Real_Time.Time_First from
Ada.Real_Time.Clock. Then you can take the resulting Time_Span and pass it to
Ada.Real_Time.To_Duration. The resulting duration (fixed point, not floating
point), can be displayed by passing it to Duration'Image. 

If you really need to, you can always convert your duration to float with a
simple numeric type conversion, but that's an unnessecary step. (Fixed-point is
your friend).

Of course you may loose some information somewhere along the way, particularly
if the delta is greater than can fit in a Time_Span. If you want a really
accurate display, you should use Split. You can then convert the Seconds_Count
to float, then call To_Duration on the Time_Span, convert it to float, and add
the two.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com
No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-10-01 13:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-30 15:01 Time to float?? Michael Andersson
2001-09-30 21:36 ` Des Walker
2001-09-30 21:56   ` Des Walker
2001-09-30 23:18 ` Robert Dewar
2001-10-01 13:54   ` Ted Dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox