std::numeric_limits::signaling_NaN

来自cppreference.com

 
 
 
类型支持
基本类型
基础类型
定宽整数类型 (C++11)
数值极限
C 数值极限接口
运行时类型信息
类型特性
类型类别
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
类型属性
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++17中过时)
(C++11)
类型特性常量
元函数
(C++17)
受支持操作
关系与属性查询
(C++11)
(C++11)
(C++11)
(C++11)
类型修改
(C++11)
(C++11)
(C++11)
类型变换
(C++11)
(C++11)
(C++17)
(C++11)(C++17中过时)
(C++17)
 
 
static T signaling_NaN()
(C++11 前)
static constexpr T signaling_NaN()
(C++11 起)
返回的特殊价值“信号不是一个数”为代表的浮点类型T。唯一有意义的,如果std::numeric_limits<T>::has_signaling_NaN == true。在IEEE 754中,最常见的浮点数字的二进制表示形式,任何值的所有位的指数集和至少一个位的馏分集表示NaN。这是实现定义的分数值代表安静或信号NaN,以及是否是有意义的符号位.
原文:
Returns the special value "signaling 不是一个数", as represented by the floating-point type T. Only meaningful if std::numeric_limits<T>::has_signaling_NaN == true. In IEEE 754, the most common binary representation of floating-point numbers, any value with all bits of the exponent set and at least one bit of the fraction set represents a NaN. It is implementation-defined which values of the fraction represent quiet or signaling NaNs, and whether the sign bit is meaningful.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

目录

[编辑] 返回值

T std::numeric_limits<T>::quiet_NaN()
/* non-specialized */ T();
bool false
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
float
实现定义的
原文:
implementation-defined
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
double
实现定义的
原文:
implementation-defined
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
long double
实现定义的
原文:
implementation-defined
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

[编辑] 例外

noexcept 规定:  
noexcept
  

[编辑] 注释

从来没有比较的NaN等于它本身。复制一个NaN,有可能不保其位表示.
原文:
A NaN never compares equal to itself. Copying a NaN may not preserve its bit representation.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
信号NaN作为一个参数传递给一个算术表达式,提出相应的浮点异常的NaN“安静”,也就是表达式返回的静态NaN.
原文:
When a signaling NaN is used as an argument to an arithmetic expression, the appropriate floating-point exception may be raised and the NaN is "quieted", that is, the expression returns a quiet NaN.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

[编辑] 示例

演示了如何使用信号NaN提出浮点异常
原文:
Demonstrates the use of a signaling NaN to raise a floating-point exception
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

#include <iostream>
#include <limits>
#include <cfenv>
#pragma STDC_FENV_ACCESS on
void show_fe_exceptions()
{
    int n = std::fetestexcept(FE_ALL_EXCEPT);
    if(n & FE_INVALID) std::cout << "FE_INVALID is raised\n";
    else if(n == 0)    std::cout << "no exceptions are raised\n";
    std::feclearexcept(FE_ALL_EXCEPT);
}
int main()
{
    double snan = std::numeric_limits<double>::signaling_NaN();
    std::cout << "After sNaN was obtained ";
    show_fe_exceptions();
    double qnan = snan * 2.0;
    std::cout << "After sNaN was multiplied by 2 ";
    show_fe_exceptions();
    double qnan2 = qnan * 2.0;
    std::cout << "After the quieted NaN was multiplied by 2 ";
    show_fe_exceptions();
    std::cout << "The result is " << qnan2 << '\n';
}

输出:

After sNaN was obtained no exceptions are raised
After sNaN was multiplied by 2 FE_INVALID is raised
After the quieted NaN was multiplied by 2 no exceptions are raised
The result is nan

[编辑] 另请参阅

鉴别能表示特殊值“有信号的非数”( NaN )的浮点类型
(公开静态成员常量) [编辑]
[静态]
返回一个安静的NaN值给定的浮点类型
原文:
returns a quiet NaN value of the given floating-point type
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

(公开静态成员函数) [编辑]