命名空间
变体
操作

std::numeric_limits<T>::denorm_min

来自 cppreference.cn
 
 
 
 
 
static T denorm_min() throw();
(直到 C++11)
static constexpr T denorm_min() noexcept;
(自 C++11 起)

如果 std::numeric_limits<T>::has_denorm != std::denorm_absent,则返回类型 T 的最小正次正规值,否则对于浮点类型返回 std::numeric_limits<T>::min(),对于所有其他类型返回 T()。仅对浮点类型有意义。

[编辑] 返回值

T std::numeric_limits<T>::denorm_min()
/* 非特化 */ T()
bool false
char 0
signed char 0
unsigned char 0
wchar_t 0
char8_t (自 C++20 起) 0
char16_t (自 C++11 起) 0
char32_t (自 C++11 起) 0
short 0
unsigned short 0
int 0
unsigned int 0
long 0
unsigned long 0
long long (自 C++11 起) 0
unsigned long long since (自 C++11 起) 0
float FLT_TRUE_MIN (2-149
if
std::numeric_limits<float>::is_iec559 is true)
double DBL_TRUE_MIN (2-1074
if
std::numeric_limits<double>::is_iec559 is true)
long double LDBL_TRUE_MIN

[编辑] 示例

演示了 denorm_min() 的底层位结构并打印值

#include <cassert>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits>
 
int main()
{
    // the smallest subnormal value has sign bit = 0, exponent = 0
    // and only the least significant bit of the fraction is 1
    std::uint32_t denorm_bits = 0x0001;
    float denorm_float;
    std::memcpy(&denorm_float, &denorm_bits, sizeof(float));
 
    assert(denorm_float == std::numeric_limits<float>::denorm_min());
 
    std::cout << "float\tmin()\t\tdenorm_min()\n";
    std::cout << "\t" << std::numeric_limits<float>::min() << '\t';
    std::cout <<         std::numeric_limits<float>::denorm_min() << '\n';
 
    std::cout << "double\tmin()\t\tdenorm_min()\n";
    std::cout << "\t" << std::numeric_limits<double>::min() << '\t';
    std::cout <<         std::numeric_limits<double>::denorm_min() << '\n';
}

可能的输出

float	min()		denorm_min()
	1.17549e-38	1.4013e-45
double	min()		denorm_min()
	2.22507e-308	4.94066e-324

[编辑] 参见

[静态]
返回给定非浮点类型的最小有限值,或给定浮点类型的最小正规值
(公共静态成员函数) [编辑]
[静态]
标识浮点类型使用的反规范化样式
(公共静态成员常量) [编辑]
[静态] (C++11)
返回给定类型的最低有限值,即有符号类型的最负值,无符号类型的 ​0​
(公共静态成员函数) [编辑]