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 生日祝福语舅舅 简短独特