Re: Real Time IO routines
- From: andrew <andrew.carroll@xxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 14:14:27 -0700
On Oct 26, 3:33 pm, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
On Fri, 26 Oct 2007 13:00:13 -0700, andrew wrote:
On Oct 26, 1:36 pm, Ludovic Brenta <ludo...@xxxxxxxxxxxxxxxxxx> wrote:
andrew writes:
Time_Unit is defined as a constant := 10#1.0#E-9, is Time_Unit then
a "real literal"? How can I convert a "real literal" to a scalar
type (maybe that's a contradiction?)?
Real literals are of the type universal_real which (a) is scalar and
(b) converts implicitly to any other floating-point type. Does that
answer your question?
To Ludovic: Ahh, so if I had to define a universal_real I could
output it using something like integer'image(it)?
To AV: I don't really know why it's necessary yet; sometimes my
subconcious mind works faster than my concious mind and I just have to
go with it. I can say though that:
-- Time and Time_Span are represented in 64-bit Duration value in
-- in nanoseconds. For example, 1 second and 1 nanosecond is
-- represented as the stored integer 1_000_000_001.
You never know, that depends on the underlying hardware and OS. Even under
the same hardware/OS there exist multiple time sources with their own
precision and accuracy.
So if a duration is represented as the stored INTEGER ... then I could
maybe use integer'image(duration), maybe?
what does this mean: type DURATION is delta implementation_defined
range implementation_defined;?
It varies from platform to platform
Is delta? what's delta?
Precision of a fixed-point type. See ARM 3.5.9.
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
Start : Time := Clock;
Period : Duration;
type Seconds is delta 0.000_001 range -1.0E10 .. 1.0E10;
-- Microsecond precision type
begin
delay 0.5;
Period := To_Duration (Clock - Start);
Put_Line ("Duration delta on this computer = " & Float'Image
(Duration'Delta));
Put_Line (Duration'Image (Period) & "s");
Put_Line (Integer'Image (Integer (Period * 1000.0)) & "ms");
-- Be careful here, as it might overflow first in the multiplication
-- and then in conversion to integer
Put_Line (Float'Image (Float (Period)) & "s");
Put_Line (Seconds'Image (Seconds (Period)) & "s");
end Test;
--
Regards,
Dmitry A. Kazakovhttp://www.dmitry-kazakov.de- Hide quoted text -
- Show quoted text -
This is all great information; thank you all those that posted.
Something seems to be wrong though. In my program I am basiclly
doing:
start := clock;
--I run my algorithm here
finish := clock;
ada.Text_IO.put_line("time = " & duration'image(to_duration(finish -
start)));
the output is always time = 0.000000000. I know it had to take some
time because it takes about 10 seconds for the program to reach that
point in the code. Overflow maybe?
.
- Follow-Ups:
- Re: Real Time IO routines
- From: John McCormick
- Re: Real Time IO routines
- From: tmoran
- Re: Real Time IO routines
- From: Adam Beneschan
- Re: Real Time IO routines
- From: Anh Vo
- Re: Real Time IO routines
- References:
- Real Time IO routines
- From: andrew
- Re: Real Time IO routines
- From: Anh Vo
- Re: Real Time IO routines
- From: andrew
- Re: Real Time IO routines
- From: Anh Vo
- Re: Real Time IO routines
- From: andrew
- Re: Real Time IO routines
- From: Ludovic Brenta
- Re: Real Time IO routines
- From: andrew
- Re: Real Time IO routines
- From: Dmitry A. Kazakov
- Real Time IO routines
- Prev by Date: Re: Real Time IO routines
- Next by Date: Re: Real Time IO routines
- Previous by thread: Re: Real Time IO routines
- Next by thread: Re: Real Time IO routines
- Index(es):