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,7a434e753b9dd044 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Time_Span divide question Date: 1997/05/19 Message-ID: #1/1 X-Deja-AN: 242381241 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <337C5D12.6230@gsfc.nasa.gov> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-05-19T00:00:00+00:00 List-Id: Stephen Leake (Stephen.Leake@gsfc.nasa.gov) wrote: : ... : Here's a compilable test: : with Text_IO; use Text_IO; : with Ada.Real_Time; use Ada.Real_Time; : with Unchecked_Conversion; : with Interfaces; : procedure Test : is : D1, D2 : Duration; : TS1, TS2 : Time_Span; : function To_Int_64 is new Unchecked_Conversion : (Source => Time_Span, : Target => Interfaces.Integer_64); : begin : D1 := 0.495; : D2 := 0.500; : Put_Line ("Duration divide result: " & : Integer'Image(Integer(D1/D2))); : TS1 := To_Time_Span (D1); : TS2 := To_Time_Span (D2); : Put_Line (" Int_64 (TS1) => " & Interfaces.Integer_64'Image : (To_Int_64 (TS1))); : Put_Line (" Int_64 (TS2) => " & Interfaces.Integer_64'Image : (To_Int_64 (TS2))); : Put_Line ("Time_Span divide result: " & Integer'Image(TS1/TS2)); : end Test; : Note that your compiler may have a different representation for : Time_Span. : Running the code on GNAT 3.09, under Windows 95 on a Pentium, I get: : Duration divide result: 0 That seems wrong. Unless the 'small for Duration is extremely large (i.e. >= 1.0), D1/D2 should be just slightly less than 1 as a universal_fixed value (the result of fixed-fixed division), and when converted to Integer, it should be rounded (per RM95 4.6(33)). : Int_64 (TS1) => 495000000 : Int_64 (TS2) => 500000000 : Time_Span divide result: 0 This one looks right. : Integer division truncates, in order to satisfy the rules in RM 4.5.5 (1 : .. 5). Fixed point division goes up or down; see RM 4.5.5(21) That is a bit misleading. Fixed-point division goes up or down when converting the universal_fixed result of division to an ordinary fixed-point value (G.2.3(10)). However, when converting to an integer value, it should be rounded to the nearest integer (away from zero if a tie). See G.2.3(18) and 4.6(33). : -- : - Stephe -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA