在线文档教程
C++
应用 | Utilities

std::numeric_limits::quiet_NaN

STD::数字[医]限制::安静[医]南

static T quiet_NaN((until C++11)
static constexpr T quiet_NaN((since C++11)

返回特殊值“静默”。无号“,由浮点类型表示。T.只有在以下情况下才有意义std::numeric_limits<T>::has_quiet_NaN==true在ieee 754中,浮点数最常见的二进制表示形式,指数集的所有位数和分数集的至少一位的任何值都代表NaN。它是实现-定义的分数的值代表安静或信令的nans,以及符号位是否有意义。

返回值

Tstd::numeric_limits::quiet_NaN()
/* non-specialized */T(
boolfalse
char​0​
signed char​0​
unsigned char​0​
wchar_t​0​
char16_t​0​
char32_t​0​
short​0​
unsigned short​0​
int​0​
unsigned int​0​
long​0​
unsigned long​0​
long long​0​
unsigned long long​0​
floatNAN or another implementation-defined NaN
doubleimplementation-defined
long doubleimplementation-defined

例外

(none)(until C++11)
noexcept specification: noexcept(since C++11)

注记

NaN从来都比不上它自己。复制NAN可能不会保留其位表示形式。

生成NaN%28输出字符串的几种方法是编译器特有的%29。

二次

#include <iostream> #include <limits> #include <cmath> int main() { std::cout << std::numeric_limits<double>::quiet_NaN() << ' ' << std::numeric_limits<double>::signaling_NaN() << ' ' << std::acos(2) << ' ' << std::tgamma(-1) << ' ' << std::log(-1) << ' ' << std::sqrt(-1) << ' ' << 0 / 0.0 << '\n'; std::cout << "NaN == NaN? " << std::boolalpha << ( std::numeric_limits<double>::quiet_NaN() == std::numeric_limits<double>::quiet_NaN() ) << '\n'; }

二次

产出:

二次

nan nan nan nan nan -nan -nan NaN == NaN? false

二次

另见

has_quiet_NaN staticidentifies floating-point types that can represent the special value "quiet not-a-number" (NaN) (public static member constant)
signaling_NaN staticreturns a signaling NaN value of the given floating-point type (public static member function)
nannanfnanl (C++11)(C++11)(C++11)not-a-number (NaN) (function)
isnan (C++11)checks if the given number is NaN (function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/type/NUMERIC[医]极限/安静[医]南