This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3] c++0x std::ratio implementation


On Fri, Jul 4, 2008 at 1:28 PM, Chris Fairles <chris.fairles@gmail.com> wrote:
> 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
>

I should also mention that the restriction of the range is due to
20.3.1 paragraph 1: "the absolute value of the template arguments N
and D shall be representable by type intmax_t". Since abs(INTMAX_MIN)
== INTMAX_MAX + 1, a diagnostic is issued if N/D == INTMAX_MIN.

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]