
Hi, In the Date-Time library, date_duration class provides a set of basic arithmetic operations. Among others there is multiplication and division. Current interface supports only integer factors. Sometimes this precision is not sufficient. I have actualy came accross such a occasion. I need to adjust the duration using a multiplier from range <0,1>. Currenly it is not feasible, and I have to workaroud it by converting to microseconds and back. Would it be possible to alter the interface, so it will be able to use real factors? Thanks. Regards, Pavol

On Mon, 22 Nov 2004 16:00:26 +0100, Pavol Droba wrote
Hi,
In the Date-Time library, date_duration class provides a set of basic arithmetic operations. Among others there is multiplication and division.
Current interface supports only integer factors. Sometimes this precision is not sufficient. I have actualy came accross such a occasion. I need to adjust the duration using a multiplier from range <0,1>. Currenly it is not feasible, and I have to workaroud it by converting to microseconds and back.
Would it be possible to alter the interface, so it will be able to use real factors?
Well date_duration is meant only to represent whole days, so even if this could be supported you would get either rounding or truncation errors. So obviously you are making some decisions on this in your user code. Also, is there a reason why you aren't just using a time_duration? Jeff

On Mon, Nov 22, 2004 at 09:37:11AM -0700, Jeff Garland wrote:
On Mon, 22 Nov 2004 16:00:26 +0100, Pavol Droba wrote
Hi,
In the Date-Time library, date_duration class provides a set of basic arithmetic operations. Among others there is multiplication and division.
Current interface supports only integer factors. Sometimes this precision is not sufficient. I have actualy came accross such a occasion. I need to adjust the duration using a multiplier from range <0,1>. Currenly it is not feasible, and I have to workaroud it by converting to microseconds and back.
Would it be possible to alter the interface, so it will be able to use real factors?
Well date_duration is meant only to represent whole days, so even if this could be supported you would get either rounding or truncation errors. So obviously you are making some decisions on this in your user code. Also, is there a reason why you aren't just using a time_duration?
Oh, sorry, I did mean time_duration. I will give an example. Imagine, that you have time_duration that spans over multiple years. Internal ticks_ value is quite large number. Now lets's say it is 1000000 ... I'd like to multily it by 0.55. It will be nice integer after the operation. But there is no other reasonable way to do if otherwise. Just in case you wondering what can be use case for such an operation, imagine a graph where x-axis represents a timeline between two timestamps. If you want to draw a grid, you will need to multiply the time difference by 0.1 0.2 0.3 and etc. Regards, Pavol

On Mon, 22 Nov 2004 19:09:38 +0100, Pavol Droba wrote
Oh, sorry, I did mean time_duration. I will give an example. Imagine, that you have time_duration that spans over multiple years. Internal ticks_ value is quite large number.
Now lets's say it is 1000000 ... I'd like to multily it by 0.55. It will be nice integer after the operation. But there is no other reasonable way to do if otherwise.
Just in case you wondering what can be use case for such an operation, imagine a graph where x-axis represents a timeline between two timestamps. If you want to draw a grid, you will need to multiply the time difference by 0.1 0.2 0.3 and etc.
Actually, I think there is an easier way. I'd calculate the difference between the 2 timestamps (divided by the number of divisions) to get the the 'step' of the grid. Then I'd create time_iterator with the calculated step to generate the values of the grid. If you haven't used the time_iterator you might have a look at: http://www.boost.org/doc/html/date_time/posix_time.html#date_time.posix_time. time_iterators Jeff

On Mon, Nov 22, 2004 at 01:39:27PM -0700, Jeff Garland wrote:
On Mon, 22 Nov 2004 19:09:38 +0100, Pavol Droba wrote
Oh, sorry, I did mean time_duration. I will give an example. Imagine, that you have time_duration that spans over multiple years. Internal ticks_ value is quite large number.
Now lets's say it is 1000000 ... I'd like to multily it by 0.55. It will be nice integer after the operation. But there is no other reasonable way to do if otherwise.
Just in case you wondering what can be use case for such an operation, imagine a graph where x-axis represents a timeline between two timestamps. If you want to draw a grid, you will need to multiply the time difference by 0.1 0.2 0.3 and etc.
Actually, I think there is an easier way. I'd calculate the difference between the 2 timestamps (divided by the number of divisions) to get the the 'step' of the grid. Then I'd create time_iterator with the calculated step to generate the values of the grid. If you haven't used the time_iterator you might have a look at:
http://www.boost.org/doc/html/date_time/posix_time.html#date_time.posix_time. time_iterators
I see, that I haven't gave the best example. I was just trying to point out the problem, unfortunately, you have provide me with solution to another one. So here is another example. Imagine a statistical system. Now the input can be arbitrary type of date. If would be very hard to make the algorithm that works for any particular type or combination of types. Therefor, data is normalized. i.e. converted to a real number from interval <0,1>. Algorithm process these normalize values and at the end results are expanded to the original types. This is a common practice when multitype data must be handled and they are intermixed. Now it is clear, that for the expansion, one need to multiply a time_duration by a real number factor. Regards, Pavol

On Mon, 22 Nov 2004 22:33:58 +0100, Pavol Droba wrote
I see, that I haven't gave the best example. I was just trying to point out the problem, unfortunately, you have provide me with solution to another one.
So here is another example.
Imagine a statistical system. Now the input can be arbitrary type of date. If would be very hard to make the algorithm that works for any particular type or combination of types. Therefor, data is normalized. i.e. converted to a real number from interval <0,1>. Algorithm process these normalize values and at the end results are expanded to the original types.
This is a common practice when multitype data must be handled and they are intermixed.
Ok, I'm not clear on why that would be, but I'll take your word for it. Personally I'd be concerned about the loss of accuracy in these conversions.
Now it is clear, that for the expansion, one need to multiply a time_duration by a real number factor.
So I take it that the data is not regular -- that is it might be 0.1, 0.4, 0.9, 0.95, etc? I'm still unsure how this interface would operate. Should I truncate or round fractional values that result? The internal representation of time_duration isn't changing from an integer to a real because that would result in a lack of correct calculation for the current operations. So this calculation will require conversion to real and back. At the moment the benefit of putting this in the library isn't outweighing the issues it raises for me (I'm still open to persuasion). I'm inclined to leave this as a user written function -- especially since I can't write it any more efficiently than you... Jeff
participants (2)
-
Jeff Garland
-
Pavol Droba