nan函数 c语言
C ++ nan()函数 (C++ nan() function)
nan() function is a library function of cmath header, it is used to get the NaN value, it returns a quiet NaN (Not-A-Number) value of double type.
nan()函数是cmath标头的库函数,用于获取NaN值,它返回双精度类型的安静NaN (非数字)值。
Syntax of nan() function:
nan()函数的语法:
nan(const char* tagp);
Parameter(s): const char* tagp – an implementation-specific C-String, it can be an empty string ("") to generate a generic NaNvalue (nan).
参数: const char * tagp –特定于实现的C-String,它可以是空字符串( “” ),以生成通用的NaN值( nan )。
Return value: double – returns the NaN value (nan) of type double.
返回值: double-返回double类型的NaN值( nan )。
Example:
例:
Function call:
nan("");
Output:
nan
C ++代码演示nan()函数的示例 (C++ code to demonstrate the example of nan() function)
// C++ code to demonstrate the example of
// nan() function
#include
#include
using namespace std;
// main() section
int main()
{
double nanValue;
//generating generic NaN value
//by passing an empty string
nanValue = nan("");
//printing the value
cout<
return 0;
}
Output
输出量
nanValue: nan
Example to print the type of NaN ("nan")
打印NaN类型(“ nan”)的示例
In C++, to print the type of a variable or value, we can use typeid() by passing the variable name or the value and the function name() with the statement typeid(variable/value) returns the type of the variable. To use these functions, we must use typeinfo header.
在C ++中,要打印变量或值的类型,我们可以使用typeid(),方法是传递变量名或值,而函数name()与语句typeid(variable / value)一起返回变量的类型。 要使用这些功能,我们必须使用typeinfo标头。
Consider this example,
考虑这个例子,
// C++ code to demonstrate the example of
// nan() function & printing the return type of nan()
#include
#include
#include //for types related functions
using namespace std;
// main() section
int main()
{
double nanValue;
//generating generic NaN value
//by passing an empty string
nanValue = nan("");
//printing the value
cout<
//printing the type of nan
cout<
return 0;
}
Output
输出量
nanValue: nan
type of nan: d
See the output – type of nan is d that is used for the double.
查看输出-nan的类型是d ,它用于double。
Reference: C++ nan() function
参考: C ++ nan()函数
翻译自: https://www.includehelp.com/cpp-tutorial/nan-function-with-example.aspx
nan函数 c语言