* Re: Time_Span divide question [not found] <5lg555$rba3@castor.cca.rockwell.com> @ 1997-05-15 0:00 ` Mark D. McKinney 1997-05-16 0:00 ` Stephen Leake 1997-05-16 0:00 ` Robert A Duff 1997-05-16 0:00 ` Tucker Taft 1 sibling, 2 replies; 10+ messages in thread From: Mark D. McKinney @ 1997-05-15 0:00 UTC (permalink / raw) > D1 := 0.495; > D2 := 0.500; > Put_Line ("Duration divide result: " & Integer'Image(Integer(D1/D2))); D1 / D2 = 0.990 Integer(D1/D2) = 1 > > TS1 := To_Time_Span (D1); > TS2 := To_Time_Span (D2); > Put_Line ("Time_Span divide result: " & Integer'Image(TS1/TS2)); To_Time_Span(D1) = Integer(D1) = 0 To_Time_Span(D2) = Integer(D2) = 1 TS1 / TS2 = 0 Yes they should be different. Careful where rounding occurs. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-15 0:00 ` Time_Span divide question Mark D. McKinney @ 1997-05-16 0:00 ` Stephen Leake 1997-05-19 0:00 ` Tucker Taft 1997-05-16 0:00 ` Robert A Duff 1 sibling, 1 reply; 10+ messages in thread From: Stephen Leake @ 1997-05-16 0:00 UTC (permalink / raw) Mark D. McKinney wrote: > > > D1 := 0.495; > > D2 := 0.500; > > Put_Line ("Duration divide result: " & Integer'Image(Integer(D1/D2))); > D1 / D2 = 0.990 > Integer(D1/D2) = 1 > > > > TS1 := To_Time_Span (D1); > > TS2 := To_Time_Span (D2); > > Put_Line ("Time_Span divide result: " & Integer'Image(TS1/TS2)); > > To_Time_Span(D1) = Integer(D1) = 0 > To_Time_Span(D2) = Integer(D2) = 1 Um, no. Time_Span is an integer type, but it is scaled, so that 1 is one Time_Unit, which is a small fraction of seconds. In GNAT, Time_Unit is one nanosecond. So To_Time_Span (foo) is NOT the same as Integer (foo). > TS1 / TS2 = 0 > > Yes they should be different. > > Careful where rounding occurs. 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 Int_64 (TS1) => 495000000 Int_64 (TS2) => 500000000 Time_Span divide result: 0 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) -- - Stephe ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-16 0:00 ` Stephen Leake @ 1997-05-19 0:00 ` Tucker Taft 1997-05-19 0:00 ` Robert Dewar 0 siblings, 1 reply; 10+ messages in thread From: Tucker Taft @ 1997-05-19 0:00 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-19 0:00 ` Tucker Taft @ 1997-05-19 0:00 ` Robert Dewar 1997-05-21 0:00 ` Kevin Radke 0 siblings, 1 reply; 10+ messages in thread From: Robert Dewar @ 1997-05-19 0:00 UTC (permalink / raw) Tuck says <<: 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)).>> That's definitely wrong. Using the latest version of GNAT on the program, the output is: Duration divide result: 1 Int_64 (TS1) => 495000000 Int_64 (TS2) => 500000000 Time_Span divide result: 0 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-19 0:00 ` Robert Dewar @ 1997-05-21 0:00 ` Kevin Radke 1997-05-25 0:00 ` Robert Dewar 0 siblings, 1 reply; 10+ messages in thread From: Kevin Radke @ 1997-05-21 0:00 UTC (permalink / raw) In article <dewar.864099351@merv>, Robert Dewar <dewar@merv.cs.nyu.edu> wrote: >Tuck says > ><<: 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)).>> > >That's definitely wrong. Using the latest version of GNAT on the program, >the output is: > >Duration divide result: 1 > Int_64 (TS1) => 495000000 > Int_64 (TS2) => 500000000 >Time_Span divide result: 0 Hmmm... 3.07 on NT was definitely broken then since it gave 0. Kevin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-21 0:00 ` Kevin Radke @ 1997-05-25 0:00 ` Robert Dewar 1997-05-27 0:00 ` Kevin Radke 0 siblings, 1 reply; 10+ messages in thread From: Robert Dewar @ 1997-05-25 0:00 UTC (permalink / raw) Kevin wrote, responding to me <<>That's definitely wrong. Using the latest version of GNAT on the program, >the output is: > >Duration divide result: 1 > Int_64 (TS1) => 495000000 > Int_64 (TS2) => 500000000 >Time_Span divide result: 0 Hmmm... 3.07 on NT was definitely broken then since it gave 0. Kevin>> First, there is no 3.07 on NT, perhaps you are talking about 3.09 on NT or the 3.07 on DOS (perhaps running on NT?) Anyway, that may well be. The correct version above is what I got from GNAT 3.10, which is the current version available to customers. We expect a code freeze for version 3.10 quite soon, and a public release of 3.10 will occur some time in the future. Robert Dewar Ada Core Technologies ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-25 0:00 ` Robert Dewar @ 1997-05-27 0:00 ` Kevin Radke 0 siblings, 0 replies; 10+ messages in thread From: Kevin Radke @ 1997-05-27 0:00 UTC (permalink / raw) In article <dewar.864583354@merv>, Robert Dewar <dewar@merv.cs.nyu.edu> wrote: >Kevin wrote, responding to me > ><<>That's definitely wrong. Using the latest version of GNAT on the program, >>the output is: >> >>Duration divide result: 1 >> Int_64 (TS1) => 495000000 >> Int_64 (TS2) => 500000000 >>Time_Span divide result: 0 > > >Hmmm... 3.07 on NT was definitely broken then since it >gave 0. > >Kevin>> > > >First, there is no 3.07 on NT, perhaps you are talking about 3.09 on NT >or the 3.07 on DOS (perhaps running on NT?) Anyway, that may well be. >The correct version above is what I got from GNAT 3.10, which is the >current version available to customers. We expect a code freeze for >version 3.10 quite soon, and a public release of 3.10 will occur some >time in the future. Alas, Robert is correct (as usual). It seems I was using 3.09 on NT (The last public release on NT), and it is the one that returns the incorrect results. I look forward for 3.10... Kevin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-15 0:00 ` Time_Span divide question Mark D. McKinney 1997-05-16 0:00 ` Stephen Leake @ 1997-05-16 0:00 ` Robert A Duff 1 sibling, 0 replies; 10+ messages in thread From: Robert A Duff @ 1997-05-16 0:00 UTC (permalink / raw) In article <337BD41B.2FE1@mail.us.net>, Mark D. McKinney <mckmark@mail.us.net> wrote: >> D1 := 0.495; >> D2 := 0.500; >To_Time_Span(D1) = Integer(D1) = 0 >To_Time_Span(D2) = Integer(D2) = 1 No, that's not right. Time_Span is an integer count of Time_Span_Units, which is less than or equal to 20 microseconds. E.g. if Time_Span_Unit = 0.000_010, then To_Time_Span(D2) will be approx 50_000 Time_Span_Units, which is half a second. - Bob ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question [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 ` Tucker Taft 1997-05-19 0:00 ` Wayne 1 sibling, 1 reply; 10+ messages in thread From: Tucker Taft @ 1997-05-16 0:00 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Time_Span divide question 1997-05-16 0:00 ` Tucker Taft @ 1997-05-19 0:00 ` Wayne 0 siblings, 0 replies; 10+ messages in thread From: Wayne @ 1997-05-19 0:00 UTC (permalink / raw) Tucker Taft writes: > >: 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. I agree. Someone told me that GNAT generates a zero. Must be a bug in GNAT (I think it was the NT one). >: 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). A Duration can be divided by a Duration. Sometimes you want a unitless result. I want to divide a time by a period to get the number of cycles. >: 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." They should be added to the next version of Ada.Real_Time, don't you think? This is very minor, but would be nice for completeness. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~1997-05-27 0:00 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [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 ` 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 ` Robert A Duff 1997-05-16 0:00 ` Tucker Taft 1997-05-19 0:00 ` Wayne
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox