Created on 2009-12-07.00:00:00 last changed 166 months ago
Proposed resolution:
Add to [ratio.ratio] synopsis
template <intmax_t N, intmax_t D = 1> class ratio { public: static constexpr intmax_t num; static constexpr intmax_t den; typedef ratio<num, den> type; };
Rationale:
Already fixed in working draft
[ Batavia: NAD EditorialResolved - see rationale below ]
[ 2010-03-27 Howard adds: ]
Daniel brought to my attention the recent addition of the typedef type to the FCD N3092:
typedef ratio type;This issue was discussed in Pittsburgh, and the decision there was to accept the typedef as proposed and move to Review. Unfortunately the issue was accidently applied to the FCD, and incorrectly. The FCD version of the typedef refers to ratio<N, D>, but the typedef is intended to refer to ratio<num, den> which in general is not the same type.
I've updated the wording to diff against N3092.
[ 2010 Pittsburgh: ]
There is no consensus to add the converting copy constructor or converting copy assignment operator. However there was consensus to add the typedef.
Proposed wording modified. Original proposed wording preserved here. Moved to Review.
Make ratio default constructible, copy-constructible and assignable from any ratio which has the same reduced form.
Add to [ratio.ratio] synopsis
template <intmax_t N, intmax_t D = 1> class ratio { public: static constexpr intmax_t num; static constexpr intmax_t den; typedef ratio<num, den> type; ratio() = default; template <intmax_t N2, intmax_t D2> ratio(const ratio<N2, D2>&); template <intmax_t N2, intmax_t D2> ratio& operator=(const ratio<N2, D2>&); };Add to [ratio.ratio]:
Two ratio classes ratio<N1,D1> and ratio<N2,D2> have the same reduced form if ratio<N1,D1>::type is the same type as ratio<N2,D2>::type
Add a new section: [ratio.cons]
Construction and assignment [ratio.cons]
template <intmax_t N2, intmax_t D2> ratio(const ratio<N2, D2>& r);Effects: Constructs a ratio object.
Remarks: This constructor shall not participate in overload resolution unless r has the same reduced form as *this.
template <intmax_t N2, intmax_t D2> ratio& operator=(const ratio<N2, D2>& r);Effects: None.
Returns: *this.
Remarks: This operator shall not participate in overload resolution unless r has the same reduced form as *this.
Change [ratio.arithmetic]
Implementations may use other algorithms to compute these values. If overflow occurs, a diagnostic shall be issued.
template <class R1, class R2> struct ratio_add { typedef see below type; };The nested typedef type shall be a synonym for ratio<T1, T2>::type where T1 has the value R1::num * R2::den + R2::num * R1::den and T2 has the value R1::den * R2::den.
template <class R1, class R2> struct ratio_subtract { typedef see below type; };The nested typedef type shall be a synonym for ratio<T1, T2>::type where T1 has the value R1::num * R2::den - R2::num * R1::den and T2 has the value R1::den * R2::den.
template <class R1, class R2> struct ratio_multiply { typedef see below type; };The nested typedef type shall be a synonym for ratio<T1, T2>::type where T1 has the value R1::num * R2::num and T2 has the value R1::den * R2::den.
template <class R1, class R2> struct ratio_divide { typedef see below type; };The nested typedef type shall be a synonym for ratio<T1, T2>::type where T1 has the value R1::num * R2::den and T2 has the value R1::den * R2::num.
CopyConstruction and Assignment between ratios having the same normalized form. Current N3000 do not allows to copy-construct or assign ratio instances of ratio classes having the same normalized form.
Two ratio classes ratio<N1,D1> and ratio<N2,D2> have the same normalized form if
ratio<N1, D1>::num == ratio<N2, D2>::num && ratio<N1, D1>::den == ratio<N2, D2>::den
This simple example
ratio<1,3> r1; ratio<3,9> r2; r1 = r2; // (1)
fails to compile in (1). Other example
ratio<1,3> r1; ratio_subtract<ratio<2,3>, ratio<1,3>>::type r2; r1 = r2;
The nested type of ratio_subtract<ratio<2,3>, ratio<1,3>> could be ratio<3,9> so the compilation could fail. It could also be ratio<1,3> and the compilation succeeds.
In [ratio.arithmetic] 3 and similar clauses
3 The nested typedef type shall be a synonym for ratio<T1, T2> where T1 has the value R1::num * R2::den - R2::num * R1::den and T2 has the value R1::den * R2::den.
the meaning of synonym let think that the result shall be a normalized ratio equivalent to ratio<T1, T2>, but there is not an explicit definition of what synonym means in this context.
Additionally we should add a typedef for accessing the normalized ratio, and change [ratio.arithmetic] to return only this normalized result.
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-05-03 22:13:16 | admin | set | messages: + msg5763 |
2010-12-05 00:09:22 | admin | set | status: nad editorial -> resolved |
2010-11-08 23:31:17 | admin | set | messages: + msg5318 |
2010-11-08 23:31:17 | admin | set | status: review -> nad editorial |
2010-10-21 18:28:33 | admin | set | messages: + msg1433 |
2010-10-21 18:28:33 | admin | set | messages: + msg1432 |
2010-10-21 18:28:33 | admin | set | messages: + msg1431 |
2009-12-07 00:00:00 | admin | create |