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 送给学长毕业祝福语简短