std::ratio_divide
类型特性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
编译时有理数算术 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
编译时整数序列 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14)
|
(C++11)
|
||||
算术 | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
ratio_divide
(C++11)
|
||||
比较 | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
在标头
<ratio>
定义
|
||
template< class R1, class R2 >
using ratio_divide = /* see below */; |
(C++11 起) | |
别名模板 std::ratio_divide
指代由 std::ratio 特化 R1
和
R2
表示的二个准确有理分数相除的结果。
结果是 std::ratio
特化 std::ratio<U, V> ,给定 Num == R1::num * R2::den 及 Denom == R1::den * R2::num (计算无算术溢出),则
U
为 std::ratio<Num,
Denom>::num 且 V
为 std::ratio<Num,
Denom>::den 。
注意
若 U
或 V
不能以 std::intmax_t
表示,则程序为病式。若 Num
或
Denom
不能表示为 std::intmax_t
,则程序为病式,除非实现生成 U
与
V
的正确值。
上述定义要求 std::ratio_divide<R1, R2> 的结果已约分到最简;例如, std::ratio_divide<std::ratio<1, 12>, std::ratio<1, 6>> 与 std::ratio<1, 2> 是同一类型。
示例
#include <iostream> #include <ratio> int main() { using two_third = std::ratio<2, 3>; using one_sixth = std::ratio<1, 6>; using quotient = std::ratio_divide<two_third, one_sixth>; std::cout << "(2/3) / (1/6) = " << quotient::num << '/' << quotient::den << '\n'; }
输出:
(2/3) / (1/6) = 4/1