該函數使用當前舍入模式將給定值舍入到最接近的整數。當前舍入模式由 fesetround() 決定。
例如:
rint(7.9) = 8;
if, fesetround(FE_DOWNWARD) then,
rint(7.9) = 7;
用法
假設一個數字 'x'。語法是:
return_type rint(data_type x);
注意:return_type 可以是 float、double 或 long double。
參數
x:值可以是浮點數或雙精度數。
返回值
它返回 x 的舍入值。
例子1
讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
#include <cfenv>
using namespace std;
int main()
{
float x=9.9;
std::cout << "Value of x is:" <<x<< std::endl;
std::cout << "Rounding to nearest,value is:" <<rint(x)<< std::endl;
fesetround(FE_UPWARD);
std::cout << "Rounding to upward,value is:" <<rint(x)<< std::endl;
fesetround(FE_DOWNWARD);
std::cout << "Rounding to downward,value is:" <<rint(x)<< std::endl;
return 0;
}
輸出:
Value of x is:9.9 Rounding to nearest,value is:10 Rounding to upward,value is:10 Rounding to downward,value is:9
相關用法
- C++ Math remquo()用法及代碼示例
- C++ Math remainder()用法及代碼示例
- C++ Math round()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
- C++ Math sinh()用法及代碼示例
- C++ Math scalbln()用法及代碼示例
- C++ Math cosh()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math rint()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。