C ++中的lrint()和llrint()
在本节中,我们将在C++中看到lrint()和llring()。首先让我们讨论一下lrint()。
该lrint()函数用于使用当前舍入模式将自变量中的分数给定值舍入为整数值。当前模式通过使用fesetround()。>=确定
此lrint()函数将double或float或integer值作为输入参数,并通过将小数部分舍入为整数部分来返回longint值。
示例
#include <cfenv>
#include <cmath>
#include <iostream>
using namespace std;
main() {
int x = 40;
long int res;
fesetround(FE_DOWNWARD); // setting rounding direction to DOWNWARD as downward
res = lrint(x);
cout << "Downward rounding of " << x << " is " << res << endl;
}输出结果
Downward rounding of 40.0235 is 40
该llrint()函数用于使用当前舍入模式将自变量中的分数给定值舍入为整数值。当前模式通过使用确定fesetround()。
此lrint()函数将double或float或integer值作为输入参数,并通过将小数部分舍入为整数部分来返回longlongint值。
示例
#include <cfenv>
#include <cmath>
#include <iostream>
using namespace std;
main(){
double a;
long int res;
fesetround(FE_UPWARD); //set rounding direction to upward
a = 40.3;
res = llrint(a);
cout << "Upward rounding of " << a << " is " << res << endl;
fesetround(FE_DOWNWARD); //set rounding direction to downward
a = 40.88;
res = llrint(a);
cout << "Downward rounding of " << a << " is " << res << endl;
}输出结果
Upward rounding of 40.3 is 41 Downward rounding of 40.88 is 40
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短