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