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