无涯教程-llrint(x)函数

50 阅读1分钟

该函数使用当前舍入模式舍入给定值,并返回long long int类型的值。

llrint - 语法

假设数字是“ x”。语法为:

long long int llrint(data_type x);

llrint - 参数

x :要四舍五入的值。

llrint - 返回值

它返回舍入后的值" x",并且该值的返回类型为long long int。

llrint - 例子1

让我们看一个简单的例子,当舍入方向为向上时。

#include <iostream>  
#include<math.h>  
#include<cfenv>  
using namespace std;  
int main()  
{  
   float x=5.3;  
   std::cout << "Value of x is :" << x<<std::endl;  
   fesetround(FE_UPWARD);  
   cout<<"Rounded value of x is :"<<llrint(x);  
    return 0;  
}  

输出:

Value of x is :5.3
Rounded value of x is :6   

llrint - 例子2

让我们看一个简单的例子,当舍入方向向下时。

#include <iostream>  
#include<math.h>  
#include<cfenv>  
using namespace std;  
int main()  
{  
   double x=7.9;  
   std::cout << "Value of x is :" << x<<std::endl;  
   fesetround(FE_DOWNWARD);  
   cout<<"Rounded value of x is :"<<llrint(x);  
    return 0;  
}  

输出:

Value of x is :7.9
Rounded value of x is :7

参考链接

www.learnfk.com/c++/cpp-mat…