1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > c语言 函数的参数传递示例_C ++中带有示例的nearint()函数

c语言 函数的参数传递示例_C ++中带有示例的nearint()函数

时间:2023-04-14 03:01:12

相关推荐

c语言 函数的参数传递示例_C ++中带有示例的nearint()函数

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语言 函数的参数传递示例

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。