std::ratio_divide
Defined in header <ratio> | | |
---|---|---|
template< class R1, class R2 > using ratio_divide = /* see below */; | | |
别名模板std::ratio_divide
表示用std::ratio
专门性R1
和R2
...
结果是std::ratio
专业化std::ratio<U, V>
,以至于Num == R1::num * R2::den
和Denom == R1::den * R2::num
%28计算,没有算术溢出%29,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()
{
typedef std::ratio<2, 3> two_third;
typedef std::ratio<1, 6> one_sixth;
typedef std::ratio_divide<two_third, one_sixth> r;
std::cout << "2/3 / 1/6 = " << r::num << '/' << r::den << '\n';
}
二次
产出:
二次
2/3 / 1/6 = 4/1
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com