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: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Simple Real_Time.Time_Span question Date: 1998/10/14 Message-ID: #1/1 X-Deja-AN: 401039558 References: <6vvsgo$rvo$1@nnrp1.dejanews.com> <7003e4$534@hacgate2.hac.com> <700ic6$q1p$1@nnrp1.dejanews.com> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1998-10-14T00:00:00+00:00 List-Id: 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...