Boost logo

Boost :

Subject: Re: [boost] [date_time] int64 overflow bug with subsecond duration
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2010-02-25 16:04:59


On 02/25/2010 11:44 PM, Zachary Turner wrote:
> On Thu, Feb 25, 2010 at 2:41 PM, Andrey Semashev
> <andrey.semashev_at_[hidden]>wrote:
>>
>> I think there was a ticket or two about this. The problem with adding the
>> parenthesis is that there's a possible truncation of the division result.
>> This may not be the case for your particular case, but I don't think this is
>> good enough as a general solution.
>>
>
> Yes, actually I thought about that later. Can we just do the division first
> then?
>
> (ss / frac_of_second) * traits_type::res_adjust()
>
> This is better, but still not as precise as using the parenthesized version
> above where the division is performed in floating point. I'm not sure which
> method is most desirable.

I don't think it's any better since both ss and frac_of_second are
integrals, so the truncation takes place anyway.

What I'm thinking of is introducing a compile-time check to see, whether
the truncation will actually take place, and then act accordingly. If
it's safe to divide first, then go with the parenthesis version. If it's
not, then either go with FP (yuck!) or some int128_t, which apparently
would have to be artifical.

> Also, why is it using int64_t instead of uint64_t?

Because duration is the result of the subtraction of two time points, I
guess. Negative durations are possible.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk