c语言 函数的参数传递示例
C ++附近的int()函数 (C++ nearbyint() function)
nearbyint() functionis a library function ofcmathheader, it is used to round the given value to an integral value based on the specified direction by fegetround() function. It accepts a value and returns the rounded integral value.
nearint()函数是cmath标头的库函数,用于通过fegetround()函数根据指定方向将给定值舍入为整数值。 它接受一个值并返回四舍五入的整数值。
Syntax of nearbyint() function:
附近的int()函数的语法:
C++11:
C ++ 11:
double nearbyint (double x);float nearbyint (float x);long double nearbyint (long double x);double nearbyint (T x);
Parameter(s):
参数:
x – represents the value to round.
x –表示要取整的值。
Return value:
返回值:
It returns value rounded to nearby integral.
它返回四舍五入到附近整数的值。
Example:
例:
Input:double x = 123.4;Function call:nearbyint(x);Output:123Input:double x = 123.5;Function call:nearbyint(x);Output:124
C ++代码来演示Nearestint()函数的示例 (C++ code to demonstrate the example of nearbyint() function)
// C++ code to demonstrate the example of// nearbyint() function#include <iostream>#include <cmath>#include <fenv.h> // for fegetround()using namespace std;int main(){double x = 0.0;cout << "Specified rounding is: ";switch (fegetround()) {case FE_DOWNWARD:cout << "Downward" << endl;break;case FE_TONEAREST:cout << "To-nearest" << endl;break;case FE_TOWARDZERO:cout << "Toward-zero" << endl;break;case FE_UPWARD:cout << "Upward" << endl;break;default:cout << "Unknown" << endl;}x = 123.4;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = 123.5;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = 123.6;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = -123.4;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = -123.5;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = -123.6;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;return 0;}
Output
输出量
Specified rounding is: To-nearestnearbyint(123.4): 123nearbyint(123.5): 124nearbyint(123.6): 124nearbyint(-123.4): -123nearbyint(-123.5): -124nearbyint(-123.6): -124
Reference: C++ nearbyint() function
参考: C ++附近的int()函数
翻译自: /cpp-tutorial/nearbyint-function-with-example.aspx
c语言 函数的参数传递示例