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 红包祝福语简短10字
18 周六早晨祝福语简短