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/16 Message-ID: #1/1 X-Deja-AN: 242813794 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <5lg555$rba3@castor.cca.rockwell.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-05-16T00:00:00+00:00 List-Id: NoJunkMailPlease wrote: : Should these print the same value? : D1 := 0.495; : D2 := 0.500; : Put_Line ("Duration divide result: " & Integer'Image(Integer(D1/D2))); The conversion form fixed point to integer requires rounding, so this will certainly give 1. : TS1 := To_Time_Span (D1); : TS2 := To_Time_Span (D2); : Put_Line ("Time_Span divide result: " & Integer'Image(TS1/TS2)); Integer division is truncating, and hence so is Time_Span divide, so this will give zero. : It is not clear to me what the RM requires of the divide operator for : two Time_Span types returning an integer. It says they should act the : same as integer operators. So they are required to truncate, like integer divide. : The compiler I'm using prints 1 for the Duration divide and zero for : the Time_Span divide. Correct or not correct? Correct. : I suspect that is correct, but why is there no divide returning a Time_Span? There is. But it represents the result of dividing a time span by an integer. Dividing a time span by a time span is clearly producing a unitless, non-time value. (E.g. seconds/seconds = unitless). : What about "rem"? This can be computed by multiplying the quotient by the divisor and subtracting it from the dividend. In retrospect, it would probably have made sense to include it and "mod" just for completeness, but probably because we were comparing with the operators on Duration, there was no dicussion of "rem" or "mod." : I guess to obtain the same functionality you have to add 0.5 to the : numerator. Any comments on why it was designed this way? Presuming you want rounding, then you will have to add 0.5 times the divisor before dividing. However, one of the primary goals of Time_Span was to get away from the rounding and general vagueries of fixed-point divide, so that the programmer has full control. You can think of Time_Span as simply a count of ticks, and treat it accordingly. -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA