std::numeric_limits<T>::lowest

来自cppreference.com
 
 
 
 
 
staticconstexpr T lowest()noexcept;
(C++11 起)

返回数值类型 T 可表示的最低有限值,即满足无其他有限值 y 符合 y < x 的有限值 x。这对于浮点数类型与 std::numeric_limits<T>::min() 不同。只对有界类型有意义。

目录

[编辑]返回值

Tstd::numeric_limits<T>::lowest()
/* 未特化 */T()
boolfalse
charCHAR_MIN
signedcharSCHAR_MIN
unsignedchar0
wchar_tWCHAR_MIN
char8_t(C++20 起)0
char16_t0
char32_t0
shortSHRT_MIN
unsignedshort0
intINT_MIN
unsignedint0
longLONG_MIN
unsignedlong0
longlongLLONG_MIN
unsignedlonglong0
float-FLT_MAX
double-DBL_MAX
longdouble-LDBL_MAX

[编辑]注解

对每个标准 C++ 浮点数类型 T 均有 std::numeric_limits<T>::lowest()==-std::numeric_limits<T>::max(),但这不必对任何第三方特化成立。

[编辑]示例

演示对于浮点数类型的 min()max()lowest()

#include <iostream>#include <limits>#include <string_view>   template<typename T>void print_twice(std::string_view type, T value){std::cout<<'\t'<< type <<":"<<std::defaultfloat<< value <<" 或 "<<std::hexfloat<< value <<'\n';}   int main(){// min()std::cout<<"std::numeric_limits<T>::min():\n"; print_twice("float", std::numeric_limits<float>::min()); print_twice("double", std::numeric_limits<double>::min()); print_twice("long double", std::numeric_limits<longdouble>::min());   // lowest()std::cout<<"std::numeric_limits<T>::lowest():\n"; print_twice("float", std::numeric_limits<float>::lowest()); print_twice("double", std::numeric_limits<double>::lowest()); print_twice("long double", std::numeric_limits<longdouble>::lowest());   // max()std::cout<<"std::numeric_limits<T>::max():\n"; print_twice("float", std::numeric_limits<float>::max()); print_twice("double", std::numeric_limits<double>::max()); print_twice("long double", std::numeric_limits<longdouble>::max());}

输出:

std::numeric_limits<T>::min(): float:1.17549e-38 或 0x1p-126 double:2.22507e-308 或 0x1p-1022 long double:3.3621e-4932 或 0x8p-16385 std::numeric_limits<T>::lowest(): float:-3.40282e+38 或 -0x1.fffffep+127 double:-1.79769e+308 或 -0x1.fffffffffffffp+1023 long double:-1.18973e+4932 或 -0xf.fffffffffffffffp+16380 std::numeric_limits<T>::max(): float:3.40282e+38 或 0x1.fffffep+127 double:1.79769e+308 或 0x1.fffffffffffffp+1023 long double:1.18973e+4932 或 0xf.fffffffffffffffp+16380

[编辑]参阅

[静态]
返回给定非浮点数类型的最小有限值,或给定浮点数类型的最小正规正值
(公开静态成员函数)[编辑]
[静态]
返回给定浮点数类型的最小正非正规值
(公开静态成员函数)[编辑]
[静态]
返回给定类型的最大有限值
(公开静态成员函数)[编辑]
close