comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Simple Real_Time.Time_Span question
Date: 1998/10/14
Date: 1998-10-14T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.98Oct14130031@spectre.mitre.org> (raw)
In-Reply-To: 700ic6$q1p$1@nnrp1.dejanews.com

In article <700ic6$q1p$1@nnrp1.dejanews.com> dennison@telepath.com writes:

 >  Thus a package billed as "Real_Time" ought to provide a portable way to get
 > a floating point value of a delta time (time_span). Where is it?

   1) You've got to be kidding!  Converting time to floating point to
do calculations is what caused problems with the Patriot system in
Dahran.

   2) Any fixed point value can be converted to any floating point
type.  The precision and accuracy will be determined by the types
involved.  You seem to be under the impression that (double-precision)
floating point will be more accurate than Duration.  Assuming that
Duration is a 64-bit fixed point type (and the annexes encourage such
an implementation), this will usually not be the case.

   3) What I suggest you do is write a short program to print out the
values of interest, then write and complain.  Actually the program you
need is very trivial:

   with Ada.Text_IO;
   with Ada.Calendar;
   with System;
   with Ada.Real_Time;
   procedure Test_Times is
     use type Ada.Real_Time.Time_Span;
     package Duration_IO is new Ada.Text_IO.Fixed_IO(Duration);
   begin
     Ada.Text_IO.Put(" Duration'Small is ");
     Duration_IO.Put(Duration'Small * 1_000_000,1,5,0);
     Ada.Text_IO.Put_Line(" microseconds.");

     Ada.Text_IO.Put(" System.Tick is ");
     Duration_IO.Put(System.Tick * 1_000,1,5,0);
     Ada.Text_IO.Put_Line(" milliseconds.");

     Ada.Text_IO.Put(" Ada.Real_Time.Time_Unit is ");
     Duration_IO.Put(Duration(Ada.Real_Time.Time_Unit * 1_000_000),1,5,0);
     Ada.Text_IO.Put_Line(" microseconds.");

     Ada.Text_IO.Put(" Ada.Real_Time.Time_Span_Unit is ");
     Duration_IO.Put(Ada.Real_Time.To_Duration
                 (Ada.Real_Time.Time_Span_Unit * 1_000_000),1,5,0);
     Ada.Text_IO.Put_Line(" microseconds.");

     Ada.Text_IO.Put(" Ada.Real_Time.Tick is ");
     Duration_IO.Put(Ada.Real_Time.To_Duration
                 (Ada.Real_Time.Tick * 1_000_000),1,5,0);
     Ada.Text_IO.Put_Line(" microseconds.");

   end Test_Times;

   On spectre, which is a SunOS machine using GNAT 3.10p I get:

spectre% test_times
 Duration'Small is 0.00100 microseconds.
 System.Tick is 1000.00000 milliseconds.
 Ada.Real_Time.Time_Unit is 0.00100 microseconds.
 Ada.Real_Time.Time_Span_Unit is 0.00100 microseconds.
 Ada.Real_Time.Tick is 1.00000 microseconds.

   Obviously you will lose nothing when converting to Duration from
Ada.Real_Time.Time_Span.  Converting from there to any floating point
will have rounding error for most values of type Time_Span.  (Some,
but not all, values of the form K * 2**(-N) will be represented
accurately.)
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  parent reply	other threads:[~1998-10-14  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 ` 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 [this message]
1998-10-14  0:00       ` Keith Thompson
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-13  0:00 ` dennison
1998-10-13  0:00 ` Tucker Taft
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