ratio_greater_equal()是C++中的內置函數,可檢查比率R1是否大於或等於比率R2。如果比率大於或等於比率2,則返回True;否則返回false。
用法:
template ratio_greater_equal
模板參數該函數接受兩個要比較的模板參數ratio1和ratio2。
返回值:如果ratio1大於或等於ratio2,則該函數返回一個布爾值,該值為true,否則返回false。
以下示例程序旨在說明上述函數:
示例1:
// C++ program to illustrate the
// ratio_greater_equal function
// when both the ratios are equal
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
typedef ratio<3, 9> ratio1;
typedef ratio<1, 3> ratio2;
// check if R1>=R2
if (ratio_greater_equal<ratio1, ratio2>::value)
cout << "3/9 is greater than or equal to 1/3";
else
cout << "3/9 is less than 1/3";
return 0;
}
輸出:
3/9 is greater than or equal to 1/3
示例2:
// C++ program to illustrate the
// ratio_greater_equal function
// to show greater than
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
typedef ratio<1, 2> ratio1;
typedef ratio<1, 3> ratio2;
// check if R1>=R2
if (ratio_greater_equal<ratio1, ratio2>::value)
cout << "1/2 is greater than or equal to 1/3";
else
cout << "1/2 is less than 1/3";
return 0;
}
輸出:
1/2 is greater than or equal to 1/3
示例3:
// C++ program to illustrate the
// ratio_greater_equal function
// to show when less than
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
typedef ratio<1, 10> ratio1;
typedef ratio<1, 8> ratio2;
// check if R1>=R2
if (ratio_greater_equal<ratio1, ratio2>::value)
cout << "1/10 is greater than or equal to 1/8";
else
cout << "1/10 is less than 1/8";
return 0;
}
輸出:
1/10 is less than 1/8
相關用法
- C++ log()用法及代碼示例
- C++ div()用法及代碼示例
- C++ fma()用法及代碼示例
- C++ map key_comp()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ imag()用法及代碼示例
- C++ real()用法及代碼示例
- C++ valarray end()用法及代碼示例
- C++ regex_iterator()用法及代碼示例
- C++ valarray cos()用法及代碼示例
- C++ valarray tan()用法及代碼示例
- C++ valarray exp()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 ratio_greater_equal() function in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。