C++ 中的 ratio_greater_equal()函数
ratio_greater_equal()是 C++ 中的一个内置函数,用于检查比率 R1 是否大于或等于比率 R2。如果比率大于或等于比率 2,则返回 True,否则返回 false。
句法:
template < class ratio1_name, class ratio2_name > ratio_greater_equal
模板参数的函数接受两个模板参数比1和比*这些都是进行比较。
返回值:该函数返回一个布尔值,如果 ratio1 大于或等于 ratio2,则该值为真,否则返回假。
下面的程序说明了上述函数:
方案一:
// C++ program to illustrate the
// ratio_greater_equal function
// when both the ratios are equal
#include
#include
using namespace std;
int main()
{
typedef ratio<3, 9> ratio1;
typedef ratio<1, 3> ratio2;
// check if R1>=R2
if (ratio_greater_equal::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
方案二:
// C++ program to illustrate the
// ratio_greater_equal function
// to show greater than
#include
#include
using namespace std;
int main()
{
typedef ratio<1, 2> ratio1;
typedef ratio<1, 3> ratio2;
// check if R1>=R2
if (ratio_greater_equal::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
方案三:
// C++ program to illustrate the
// ratio_greater_equal function
// to show when less than
#include
#include
using namespace std;
int main()
{
typedef ratio<1, 10> ratio1;
typedef ratio<1, 8> ratio2;
// check if R1>=R2
if (ratio_greater_equal::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