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 好听的元旦简短祝福语