std::ratio_subtract
来自cppreference.com
![]() |
该页由英文版维基使用谷歌翻译机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击此处。 |
。模板别名
std::ratio_subtract
表示std::ratio的实例所代表的两个精确合理的分数相减的结果R1
和R2
,结果一个std::ratio例如std::ratio<Num, Denom>
其中Num == R1::num * R2::den - R2::num * R1::den和Denom == R1::den * R2::den.原文:
The template alias
std::ratio_subtract
denotes the result of subtracting two exact rational fractions represented by the std::ratio instances R1
and R2
. The result a std::ratio instance std::ratio<Num, Denom>
where Num == R1::num * R2::den - R2::num * R1::den and Denom == R1::den * R2::den.。会员类型。
Definition | |
type
|
std::ratio<num, den> |
。会员常数。
num [静态] |
(公开静态成员常量) |
den [静态] |
(公开静态成员常量) |
。为例。
运行此代码
#include <iostream> #include <ratio> int main() { typedef std::ratio<2, 3> two_third; typedef std::ratio<1, 6> one_sixth; typedef std::ratio_subtract<two_third, one_sixth> diff; std::cout << "2/3 - 1/6 = " << diff::num << '/' << diff::den << '\n'; }
输出:
2/3 - 1/6 = 1/2