首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::numeric_limits::tinyness_before

static const bool tinyness_before;

?

(until C++11)

static constexpr bool tinyness_before;

?

(since C++11)

价值std::numeric_limits<T>::tinyness_beforetrue适用于所有浮点类型。T这是在四舍五入前的下垫流浮点表达式的测试结果。

标准专业化

T

value of std::numeric_limits<T>::tinyness_before

/* non-specialized */

false

bool

false

char

false

signed char

false

unsigned char

false

wchar_t

false

char16_t

false

char32_t

false

short

false

unsigned short

false

int

false

unsigned int

false

long

false

unsigned long

false

long long

false

unsigned long long

false

float

implementation-defined

double

implementation-defined

long double

implementation-defined

注记

符合标准的ieee 754浮点实现被要求检测浮点下溢,并且有两种情况下可以这样做。

1%29下溢率为28%FE_UNDERFLOW如果计算产生的绝对值(如指数范围和精度均无界)小于std::numeric_limits<T>::min().这种实现在舍入%28例如之前检测到微小性。超魔法,能量%29。

2%29下溢率为28%FE_UNDERFLOW如果将结果舍入到目标浮点类型%28,即舍入到std::numeric_limits<T>::digits位数%29,结果%27s绝对值小于std::numeric_limits<T>::min()形式上,非零结果的绝对值(如指数范围为无界)小于std::numeric_limits<T>::min().这样的实现在舍入%28例如之后检测到微小。SuperSparc%29

最大次法线数由大于1.0的机器epsilon乘法得到的最小值为0x0。四舍五入前为1022,四舍五入后为正常值1p-1022。用于执行此测试的实现%28IBMPower 7%29在舍入前检测到微小。

二次

代码语言:javascript
复制
#include <iostream>
#include <limits>
#include <cmath>
#include <cfenv>
int main()
{
    std::cout << "Tinyness before: " << std::boolalpha
              << std::numeric_limits<double>::tinyness_before << '\n';
 
    double denorm_max = std::nextafter(std::numeric_limits<double>::min(), 0);
    double multiplier = 1 + std::numeric_limits<double>::epsilon();
 
    std::feclearexcept(FE_ALL_EXCEPT);
 
    double result = denorm_max*multiplier; // Underflow only if tinyness_before
 
    if(std::fetestexcept(FE_UNDERFLOW))
        std::cout << "Underflow detected\n";
 
    std::cout << std::hexfloat << denorm_max << " x " << multiplier  <<  " = "
              << result << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Tinyness before: true
Underflow detected
0xf.ffffffffffffp-1030 x 0x1.0000000000001p+0 = 0x1p-1022

二次

另见

has_denorm_loss static

identifies the floating-point types that detect loss of precision as denormalization loss rather than inexact result (public static member constant)

has_denorm static

identifies the denormalization style used by the floating-point type (public static member constant)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com