std::numeric_limits<T>::lowest
來自 cppreference.com
static constexpr T lowest() noexcept; |
(C++11 起) | |
返回數值型別 T
所能表示的最小有限值,即一個有限值 x,使得不存在另一個有限值 y 滿足 y < x。這對於浮點型別與 std::numeric_limits<T>::min() 不同。僅對有界型別有意義。
目錄 |
[編輯] 返回值
T
|
std::numeric_limits<T>::lowest() |
/* 未特化 */ | T() |
bool | false |
char | CHAR_MIN |
signed char | SCHAR_MIN |
unsigned char | 0 |
wchar_t | WCHAR_MIN |
char8_t (C++20起) | 0 |
char16_t | 0 |
char32_t | 0 |
short | SHRT_MIN |
unsigned short | 0 |
int | INT_MIN |
unsigned int | 0 |
long | LONG_MIN |
unsigned long | 0 |
long long | LLONG_MIN |
unsigned long long | 0 |
float | -FLT_MAX |
double | -DBL_MAX |
long double | -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 << " or " << 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<long double>::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<long double>::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<long double>::max()); }
輸出
std::numeric_limits<T>::min(): float: 1.17549e-38 or 0x1p-126 double: 2.22507e-308 or 0x1p-1022 long double: 3.3621e-4932 or 0x8p-16385 std::numeric_limits<T>::lowest(): float: -3.40282e+38 or -0x1.fffffep+127 double: -1.79769e+308 or -0x1.fffffffffffffp+1023 long double: -1.18973e+4932 or -0xf.fffffffffffffffp+16380 std::numeric_limits<T>::max(): float: 3.40282e+38 or 0x1.fffffep+127 double: 1.79769e+308 or 0x1.fffffffffffffp+1023 long double: 1.18973e+4932 or 0xf.fffffffffffffffp+16380
[編輯] 參閱
[靜態] |
返回給定非浮點型別的最小有限值,或給定浮點型別的最小正規化值 (public static member function) |
[靜態] |
返回給定浮點型別的最小正非正規化值 (public static member function) |
[靜態] |
返回給定型別的最大有限值 (public static member function) |