comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Time_Span divide question
Date: 1997/05/16
Date: 1997-05-16T00:00:00+00:00	[thread overview]
Message-ID: <EAA2y5.9sw.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 5lg555$rba3@castor.cca.rockwell.com


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




  parent reply	other threads:[~1997-05-16  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5lg555$rba3@castor.cca.rockwell.com>
1997-05-15  0:00 ` Time_Span divide question Mark D. McKinney
1997-05-16  0:00   ` Robert A Duff
1997-05-16  0:00   ` Stephen Leake
1997-05-19  0:00     ` Tucker Taft
1997-05-19  0:00       ` Robert Dewar
1997-05-21  0:00         ` Kevin Radke
1997-05-25  0:00           ` Robert Dewar
1997-05-27  0:00             ` Kevin Radke
1997-05-16  0:00 ` Tucker Taft [this message]
1997-05-19  0:00   ` Wayne
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox