This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] c++0x std::ratio implementation
On Fri, Jul 4, 2008 at 1:10 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
>> Updated patch. Formatting, use _GLIBCXX_USE_C99_STDINT_TR1,
>> renamed template params.
>
> Thanks. I'm finishing regtesting the patch + some minor local tweaks. While I do that, can you please double check that ratio_subtract is OK when _R2::num == INTMAX_MIN? I see an unconditional unary minus which in principle could overflow...
>
> Thanks,
> Paolo.
>
>
I don't think its an issue because you can't even construct a ratio
with num/den == INTMAX_MIN for exactly that reason. That is:
ratio_subtract<ratio<0>, ratio<INTMAX_MIN>>::type
will fail during the instantiation of ratio<INTMAX_MIN> due to:
static_assert(_Num > INTMAX_MIN && _Den > INTMAX_MIN, "out of range");
(line 137 of <ratio>)
This forces the range of num/den to -INTMAX_MAX (or INTMAX_MIN + 1) <=
num,den <= INTMAX_MAX.
ratio_subtract<ratio<0>,ratio<INTMAX_MIN+1>>::type works fine with the
result being ratio<INTMAX_MAX>.
Chris