c语言 函数的参数传递示例
C ++ isnormal()函数 (C++ isnormal() function)
isnormal() function is a library function of cmath header, it is used to check whether the given value is a normal value i.e. the value should not be infinity, NaN, Zero, or subnormal. It accepts a value (float, double or long double) and returns 1 if the given value is a normal value; 0, otherwise.
isnormal()函数是cmath标头的库函数,用于检查给定值是否为正常值,即该值不应为无穷大,NaN,零或次正规。 它接受一个值( float , double或long double ),如果给定值是正常值,则返回1;否则,返回1。 0,否则。
Syntax of isnormal() function:
isnormal()函数的语法:
In C99, it has been implemented as a macro,
在C99中,它已实现为宏,
macro isnormal(x)
In C++11, it has been implemented as a function,
在C ++ 11中,它已作为函数实现,
bool isnormal (float x);
bool isnormal (double x);
bool isnormal (long double x);
Parameter(s):
参数:
x – represents the value to be checked as normal value.
x –表示要检查的值为正常值。
Return value:
返回值:
The returns type of this function is bool, it returns 1 if the x value is a normal value; 0, otherwise.
该函数的返回类型为bool ,如果x值为正常值,则返回1;否则,返回1。 0,否则。
Example:
例:
Input:
float x = 1.0f;
Function call:
isnormal(x);
Output:
1
Input:
float x = sqrt(-1.0f);
Function call:
isnormal(x);
Output:
0
Input:
float x = 0.0f;
Function call:
isnormal(x);
Output:
0
C ++代码演示isnormal()函数的示例 (C++ code to demonstrate the example of isnormal() function)
// C++ code to demonstrate the example of
// isnormal() function
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "isnormal(0.0f)) : " << isnormal(0.0f) << endl;
cout << "isnormal(0.0f/0.0f) : " << isnormal(0.0f / 0.0f) << endl;
cout << "isnormal(0.0f/1.0f) : " << isnormal(0.0f / 1.0f) << endl;
cout << "isnormal(1.0f) : " << isnormal(1.0f) << endl;
cout << "isnormal(sqrt(-1.0f)): " << isnormal(sqrt(-1.0f)) << endl;
float x = sqrt(-1.0f);
// checking using the condition
if (isnormal(x)) {
cout << x << " is normal value." << endl;
}
else {
cout << x << " is not normal value." << endl;
}
x = sqrt(2);
if (isnormal(x)) {
cout << x << " is normal value." << endl;
}
else {
cout << x << " is not normal value." << endl;
}
return 0;
}
Output
输出量
isnormal(0.0f)) : 0
isnormal(0.0f/0.0f) : 0
isnormal(0.0f/1.0f) : 0
isnormal(1.0f) : 1
isnormal(sqrt(-1.0f)): 0
-nan is not normal value.
1.41421 is normal value.
Reference: C++ isnormal() function
翻译自: https://www.includehelp.com/cpp-tutorial/isnormal-function-with-example.aspx
c语言 函数的参数传递示例